组合数据类型综合练习:英文词频统计
字符串:
str1 = 'abcd' for i in str1: print(i)
列表:
str2 = ['a','b',['c','d']] for i in str2: print(i)
元组:
str3 = ('a','b',['c','d']) for i in str3: print(i)
字典:
name = ['a','b','c'] score = [90,80,70] dict1 = dict(zip(name,score)) print(dict1) for i in dict1: print(i)
集合:
str4 = [1,1,2,3,3,4,5,5,6] str4 = set(str4) for i in str4: print(i)
总结列表、元组、字典、集合的联系和区别:
列表可以用 [] 括起来,元组是用()括起来,字典集合是都是用{}括起来
列表是可变序列,可以索引查找元素进行增删,而元组是只读列表,数据不可修改
字典是一对对键值对组成,键唯一值不唯一,集合是由无序且不重复的数据组成