要优雅,七个Python代码的小技巧
enumerate
1 | cites = ['Shanghai', 'London', 'New York', 'Beijing'] |
zip
1 | x_list = [1, 3, 5] |
swap
1 | # bad way |
dict default value
1 | ages = { |
if no break occurred
1 | needle = 'd' |
read line
1 | # bad way |
try except else
1 | try: |
参考:视频