TypeError: unhashable type: 'list' when using built-in set function

前端 未结 4 973
死守一世寂寞
死守一世寂寞 2020-11-27 14:57

I have a list containing multiple lists as its elements

eg: [[1,2,3,4],[4,5,6,7]]

If I use the built in set function to remove duplicates f

4条回答
  •  再見小時候
    2020-11-27 15:44

    Definitely not the ideal solution, but it's easier for me to understand if I convert the list into tuples and then sort it.

    mylist = [[1,2,3,4],[4,5,6,7]]
    mylist2 = []
    for thing in mylist:
        thing = tuple(thing)
        mylist2.append(thing)
    set(mylist2)
    

提交回复
热议问题