Interleave different length lists, elimating duplicates, and preserve order

后端 未结 6 1816
一整个雨季
一整个雨季 2021-02-11 22:12

I have two lists, let\'s say:

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


        
6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-11 23:01

    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.

提交回复
热议问题