Remove sublist duplicates including reversed

后端 未结 7 1648
眼角桃花
眼角桃花 2020-12-07 04:27

For example i have following

list = [[\'1\', \'2\'], [\'1\', \'3\'], [\'1\', \'4\'], [\'1\', \'5\'], [\'2\', \'1\'], [\'4\', \'1\'], [\'2\', \'6\']]
         


        
7条回答
  •  感动是毒
    2020-12-07 04:49

    You can try this also:-

    l = [['1', '2'], ['1', '3'], ['1', '4'], ['1', '5'], ['2', '1'], ['4', '1'], ['2', '6']]
    res = []
    
    for sub_list in l:
        if sub_list[::-1] not in res:
            res.append(sub_list)
    
    print(res)
    

    Output:-

    [['1', '2'], ['1', '3'], ['1', '4'], ['1', '5'], ['2', '6']]
    

提交回复
热议问题