Home>

### How to merge sets

``````ids= {'user1': [213, 213, 213, 15, 213],
'user2': [54, 54, 119, 119, 119],
'user3': [213, 98, 98, 35]}
for i in ids.values():
i1= set(i)
print(i1)
``````

I sorted the lists by turning them into sets, so that there would be no repetitions in the lists. Now I need to put all these sets in one list, I could do it through '|' , but all these sets are already in one variable. Tell me how to do it? Maybe you need to do it differently?

It is not clear what specific result you want to get in the end? List of numbers? Lots of numbers? List of sets of numbers?

andreymal2022-02-13 12:57:36

List of numbers, now sets

Диана Тихонова2022-02-13 13:02:17
• Answer # 1

You can do this:

``````ids= {
'user1': [213, 213, 213, 15, 213],
'user2': [54, 54, 119, 119, 119],
'user3': [213, 98, 98, 35],
}
result= set()
for i in ids.values():
result |= set(i)
print(result)
``````
• Answer # 2

You can do this:

``````ids= {
'user1': [213, 213, 213, 15, 213],
'user2': [54, 54, 119, 119, 119],
'user3': [213, 98, 98, 35],
}
result= set()
for i in ids.values():
result |= set(i)
print(result)
``````