1.set:set去重的前提是,里面的值必须是不可变的数据类型,
可以把元素编程字符串后来做,也可以用eval()
["[1,23]","[1,23]"]
2.dict fromkeys 字典的key
3.循环:添加的方式,删除的方式
涉及的知识点:引用赋值,深浅拷贝
list_a =[1,1,1,2,3] list_b =list_a.copy() for i in list_a: n =list_a.count(i) for j in range(n-1): list_b.remove(i)
>>> a= ["huhongqiang","zhangsan","lisi","wangwu","wuda","ziliao"] >>> [repr(a).count(i) for i in a] [1, 1, 1, 1, 1, 1] >>> [repr(a).count(i[0]) for i in a] [3, 2, 2, 3, 3, 2] >>> ["%s:%s" %(i[0],repr(a).count(i[0])) for i in a] ['h:3', 'z:2', 'l:2', 'w:3', 'w:3', 'z:2']