列表List
1 | squares = [] |
list comprehension
1 | squares = [i * i for i in range(10)] |
new_list = [expression for member in iterable (if conditional) ]
带条件的list comprehension可以实现map(), filter()的功能
如果不是简单过滤,而是要改变某类值,可以把条件放到前面
new_list = [expression (if conditional) for member in iterable]
词典Dict
定义dict
1 | d = { |
操作dict
1 | #读取 |