Interleave different length lists, elimating duplicates, and preserve order

后端 未结 6 2283
青春惊慌失措
青春惊慌失措 2021-02-11 22:00

I have two lists, let\'s say:

keys1 = [\'A\', \'B\', \'C\', \'D\', \'E\',           \'H\', \'I\']
keys2 = [\'A\', \'B\',           \'E\', \'F\', \'G\', \'H\',            


        
6条回答
  •  -上瘾入骨i
    2021-02-11 22:53

    I would use a Set (cf. python doc), that I'd fill with the elements of the two lists, one aafter the other.

    And make a list from the Set when it's done.

    Note that there is a contradiction/paradox in your question: you want to preserve order for elements that cannot be compared (only equality because "they are complex strings" as you said).

    EDIT: the OP is right noticing that sets don't preserve order of insertion.

提交回复
热议问题