-1

I have several list with dates written as strings in the format "2017-05-22 04:35:00". All lists are ordered. I want to create a new list with dates that are present in ALL other lists.

I have been using the following code:

new_dates = list(set(a)&set(b)&set(c)&set(d))

Apparently it is working, but the resulting list is not in chronological order anymore. Any idea why this is happening?

  • 2
    Sets are hashtables and therefore generally unordered. – Norrius Feb 18 '19 at 19:13
  • 2
    Sets are "Unordered collections of distinct hashable objects" [python docs](https://docs.python.org/3/library/stdtypes.html#set-types-set-frozenset) – ktzr Feb 18 '19 at 19:14

1 Answers1

1

Just convert them back to an ordered list when you're done:

new_dates = sorted(set(a) & set(b) & set(c) & set(d))
mVChr
  • 49,587
  • 11
  • 107
  • 104