python笔记本

生活不易,考试叹气

  • 《Python 编程从入门到实践》是Python 3.5 版本,而在Python 3.6 改写了 dict 的内部算法,因此 3.6 的 dict 是有序的,在此版本之前皆是无序参考链接

  • 字符串格式化 f'Results of the {event}'

  • python列表原地赋值(id不变):nums[:] = nums[-k:] + nums[:-k]

  • LeetCode 加一题目

  • pre_sum 数字技巧

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    class Solution(object):
    def pivotIndex(self, nums):
    """
    :type nums: List[int]
    :rtype: int
    """
    sums = sum(nums)
    pre_sum = 0
    for i in range(len(nums)):
    if pre_sum * 2 + nums[i] == sums:
    return i
    pre_sum += nums[i]
    return -1