列表
[2, 'Jump Shot', 'Los Angeles Lakers']
kobe_list = [2, 'Jump Shot', 'Los Angeles Lakers']
kobe_list.append('POR')
kobe_list.remove(2)
del kobe_list[-2]
kobe_list.pop(-2)
kobe_list.insert(1, 'something')
kobe_list[1:10:2]
kobe_list[-5:-2]
lst = [i**2 for i in range(5)]
lst2 = [i - mean for i in lst]
元组
(2, 'Jump Shot', 'Los Angeles Lakers')
字典
{1: 'Jump Shot',
2: 'Jump Shot',
3: 'Jump Shot',
4: 'Jump Shot',
5: 'Jump Shot'}
shot_id = [1,2,3]
shot_zone_area = ['Right Side', 'Left Side', 'Left Side Center']
for key, value in zip(shot_id, shot_zone_area):
kobe_dict[key] = value
kobe_dict.get(5)
kobe_dict.get(5,-1)
key in kobe_dict
kobe_dict.has_key(5)
kobe_dict.keys()
kobe_dict.values()
del kobe_dict[1]
kobe_dict.pop(2)
kobe_dict.clear()
集合
- 集合是无序集合,是一组键的集合,不存储值;
- 不允许存在重复的键,可用于去除重复值;
- 可以进行数学集合运算,交、并、差等。
set(['Driving Dunk Shot', 'Running Jump Shot', 'Jump Shot'])
shot_type_set = set()
shot_type_set = {'Driving Dunk Shot', 'Running Jump Shot', 'Jump Shot'}
shot_type_set1 = {'Driving Dunk Shot', 'Running Jump Shot', 'Jump Shot'}
shot_type_set2 = {'Layup Shot', 'Driving Layup Shot'}
shot_type_set1 | shot_type_set2
shot_type_set1 & shot_type_set2
shot_type_set1 - shot_type_set2
shot_type_set1 ^ shot_type_set2