Is there a way to use Python collection right away?

Asked 2 years ago, Updated 2 years ago, 14 views

I'm sorry ㅜ 내용 I modified the contents.

a = set([1,2,3,4,5])
b = set([6,7,8,9,10])
c = a|b
print(c)

If you create a set like this, you can immediately find the desired value with slicing in the list, but I know that you can't use slicing like the list because the set allows duplication and there's no order In this case, how do I use the set value right away like a list?

python

2022-09-22 11:05

1 Answers

It is said that values stored in the collection data type must be converted into lists or tuples to access indexing.

Collective data types that do not allow duplication are often used as filters to eliminate duplication of data types, although you may want to check if certain values are in the set and use them, but if you want to use slicing, it might be better to just convert them into lists.

(Source: Park Eung-yong - <Jump to Python> Chapter 2, 6. Collective data type )


2022-09-22 11:05

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.