python笔记本
生活不易,考试叹气
《Python 编程从入门到实践》是Python 3.5 版本,而在Python 3.6 改写了 dict 的内部算法,因此 3.6 的 dict 是有序的,在此版本之前皆是无序。 参考链接
字符串格式化
f'Results of the {event}'
python列表原地赋值(id不变):
nums[:] = nums[-k:] + nums[:-k]
1
2
3
4
5
6
7
8
9
10
11
12
13class 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
作者:Yuesir
本文链接:https://vccv.cc/article/python-notebook.html
版权声明:本博客所有文章除特别声明外,均采用 CC BY-NC-ND 4.0 许可协议,转载请注明出处!