Python Practice › Function Programs › Program 22
Unique values with dict.fromkeys
Write a Python function to get the unique values of a list in order.
Input
[4, 6, 1, 7, 6, 1, 5]
Output
[4, 6, 1, 7, 5]
Approach
list(dict.fromkeys(items)).
Solution
def unique(items): return list(dict.fromkeys(items)) print(unique([4, 6, 1, 7, 6, 1, 5]))Output
[4, 6, 1, 7, 5]
Learn the concept
New to this topic? Read the lesson, then come back.