79677094

Date: 2025-06-24 06:32:09
Score: 1
Natty:
Report link

Using dict.fromkeys()

Starting from Python 3.7, dictionaries preserve insertion order by language specification (it also works in CPython 3.6, but was technically an implementation detail). So this is a clean one-liner for lists with hashable elements:

my_list = [1, 2, 2, 3, 1]

result = list(dict.fromkeys(my_list))

print(result) # Output: [1, 2, 3]

Reasons:
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: ADITYA BHARADE