列表、元组、字典、集合的定义与操作
l =['Michael', 'Bob', 'Tracy'] l.append('Bob') l.pop() print(l) t = ('Michael', 'Bob', 'Tracy') scores = [90, 80, 70] d = {'Michael': 90,'Bob': 80, 'Tracy': 70 } d ['Bob'] = 95 d['Rose'] = 60 d.pop('Bob') print(d) s1 = {'Michael', 'Bob', 'Tracy'} s2 = {1, 2, 3} print(s1,s2) print(s1 | s2) print(s1 & s2) dl = dict(zip(l,scores))

描述列表,元组,字典,集合的联系与区别:

totalStr = '201709090030周佩莹 201709090044方忻仪 201709090067黄嘉欣 201709090028粱梓蕙 201709090075胡铭炜 ' totalList = totalStr.split(' ') totalSet = set(totalList) print(totalList) print(totalSet) totalDict = {} for s in totalSet: totalDict[s]= totalList.count(s) print(totalDict)


浙公网安备 33010602011771号