How to remove duplicate tuples from a list in python?

前端 未结 4 2070
伪装坚强ぢ
伪装坚强ぢ 2021-01-03 11:22

I have a list that contains list of tuples as follows.

mylist = [[\'xxx\', 879], [\'yyy\', 315], [\'xxx\', 879], [\'zzz\', 171], [\'yyy\', 315]]
4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-03 12:02

    Another option:

    >>> mylist = [['xxx', 879], ['yyy', 315], ['xxx', 879], ['zzz', 171], ['yyy', 315]]
    >>> y = []
    >>> for x in mylist:
    ...     if not x in y:
    ...             y+=[x]
    ...
    >>> y
    [['xxx', 879], ['yyy', 315], ['zzz', 171]]
    

提交回复
热议问题