+ 2

can anyone explain this code in python

from collections import OrderedDict numbers=[5,3,2,1,3,4,4,6] print(list(OrderedDict.fromkeys(numbers))) output: [5, 3, 2, 1, 4, 6]

28th Apr 2020, 1:02 PM
Sujithra
1 Antwort
+ 5
In this code OrderedDict is used, but you will have the same effect with just using dict instead. The reason for this output is, that dicts can not have duplicated keys. List numbers do have duplicated values: 3 and 4. As all duplicates in keys will be omitted, the result will be as shown.
28th Apr 2020, 1:42 PM
Lothar
Lothar - avatar