Issue
I have a list of tuples:
[(1,2), (5,10), (2,5)]
And I would like to get a list of unique numbers
[1,2,5,10]
May I know how can I achieve that?
Solution
Will this work? I've appended each item to a new list, then use set()
to get the unique items
new_lis = []
lis = [(1,2),(5,10),(2,5)]
for x,y in lis:
new_lis.append(x)
new_lis.append(y)
result = list(set(new_lis))
[1, 2, 10, 5]
Answered By - Adrian Ang
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.