• python 基础语法


    Python3 基础语法

    https://www.runoob.com/python3/python3-multithreading.html

    重点复习

    list = [ 'abcd', 786 , 2.23, 'runoob', 70.2 ]

    tinylist = [123, 'runoob']

    print (list)

    # 输出完整列表

    print (list[0])

    # 输出列表第一个元素

    print (list[1:3])

    # 从第二个开始输出到第三个元素

    print (list[2:])

    # 输出从第三个元素开始的所有元素

    print (tinylist * 2)

    # 输出两次列表

    print (list + tinylist)

    # 连接列表

    列表和字符串

    >>> s=['1','23','2333']
    >>> s[::-1],倒叙不长为1,2,3,4,n
    ['2333', '23', '1']
    >>> s[::1]正序选择
    ['1', '23', '2333']

    [x+2 for x in [2,3,4]]

    {x:x**2 for x in [2,4,6]}

    字符串,列表,元组,集合:的操作

    字典;

    字典使用:

    https://www.runoob.com/python/att-dictionary-get.html

    Python 字典(Dictionary) get()方法


    描述

    Python 字典(Dictionary) get() 函数返回指定键的值,如果值不在字典中返回默认值。

    语法

    get()方法语法:

    dict.get(key, default=None)
    dict.get方法的使用可以有效解决在dict默认字典忘记校验是否存在而出现的索引溢出的现象
    2、列表的extend方法链接列表的时间要比使用简单append的方式时间要长,尽量自己遍历时间进行列表合并。
            for z in range(len(nums), 0, -1):
                if z in dictb:
                    for res in dictb[z]:
                        result.append(res)
    class Solution:
        def topKFrequent(self, nums: List[int], k: int) -> List[int]:
            dicta = {}
            dictb = {}
            for key in nums:
                dicta[key] = dicta.get(key,0)+1

            for index, value in dicta.items():
                if value in dictb:
                    dictb[value].append(index)
                else:
                    dictb[value]=[index]

            result = []
            for z in range(len(nums), 0, -1):
                if z in dictb:
                    for res in dictb[z]:
                        result.append(res)

            return result[:k]

    python split()方法:

    https://www.runoob.com/python3/python3-string-split.html

    这里split函数可以默认自动按照所有空格字符切割,不用单独自己设置字符

  • 相关阅读:
    Ubuntu下cc和gcc的关系
    Ubuntu下makefile的简单使用
    Ubuntu下配置Apache以及搭载CGI
    Easy C 编程 in Linux
    Ubuntu下配置GitHub
    Ubuntu学习之路2
    Ubuntu下配置Java环境
    Vim学习之路1
    将博客搬至CSDN
    ubuntu连接手机的方法
  • 原文地址:https://www.cnblogs.com/xinghaiyige/p/12302789.html
Copyright © 2020-2023  润新知