How to construct a set out of list items in python?

前端 未结 6 1941
无人共我
无人共我 2020-11-27 12:25

I have a list of filenames in python and I would want to construct a set out of all the filenames.

filelist=[]
for filename in file         


        
6条回答
  •  情话喂你
    2020-11-27 12:46

    Here is another solution:

    >>>list1=["C:\\","D:\\","E:\\","C:\\"]
    >>>set1=set(list1)
    >>>set1
    set(['E:\\', 'D:\\', 'C:\\'])
    

    In this code I have used the set method in order to turn it into a set and then it removed all duplicate values from the list

提交回复
热议问题