Python Forum
merging lists, dedup and keeping order, in older pythons
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
merging lists, dedup and keeping order, in older pythons
#2
Sets don't keep order and python doesn't include built-in ordered sets. But you can use ordered dictionary from the collections package which is also in Python 2:

from collections import OrderedDict

list1 = ["one", "two"]
list2 = ["three", "four"]

merge = OrderedDict()

for a_list in [list1, list2]:
    for item in a_list:
        merge[item] = None

print(merge.keys())
Sets stay unordered in Python 3.7 :)
Reply


Messages In This Thread
RE: merging lists, dedup and keeping order, in older pythons - by ODIS - Oct-11-2018, 03:21 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  keeping logs for every success fail attempt robertkwild 22 6,226 Jul-19-2024, 03:49 PM
Last Post: robertkwild
  Installing Older Version Of Numpy & Pandas knight2000 6 23,368 Aug-30-2023, 10:58 AM
Last Post: knight2000
  Keeping up with IDEs and Virtual Environments... bytecrunch 7 7,751 Sep-05-2022, 08:04 PM
Last Post: snippsat
  Keeping a value the same despite changing the variable it was equated to TheTypicalDoge 2 2,405 Mar-13-2022, 10:50 PM
Last Post: Yoriz
  Generate a string of words for multiple lists of words in txt files in order. AnicraftPlayz 2 4,160 Aug-11-2021, 03:45 PM
Last Post: jamesaarr
  coding problem from older book teddfirth 3 2,973 Mar-06-2021, 03:51 PM
Last Post: teddfirth
  how to pass arguments between pythons scripts? electricDesire 2 3,105 Oct-19-2020, 07:19 PM
Last Post: electricDesire
  Split dict of lists into smaller dicts of lists. pcs3rd 3 3,434 Sep-19-2020, 09:12 AM
Last Post: ibreeden
  Problem keeping the window up benlyboy 11 6,415 Jan-24-2020, 02:12 AM
Last Post: tamilselvisubbiah
  remove files from folder older than X days kerzol81 2 10,923 Jan-03-2020, 11:55 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020