Unique values with dict.fromkeys

EasyFunction Programs · 22 of 39

Write a Python function to get the unique values of a list in order.

Advertisement
Input
[4, 6, 1, 7, 6, 1, 5]
Output
[4, 6, 1, 7, 5]

Approach

  1. list(dict.fromkeys(items)).

Solution

Python
def unique(items):    return list(dict.fromkeys(items)) print(unique([4, 6, 1, 7, 6, 1, 5]))
Output
[4, 6, 1, 7, 5]
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More function programs

← All 39 Function Programs