M
M
Michael2014-05-03 00:38:19
Python
Michael, 2014-05-03 00:38:19

Working with python sets

Hello, how can I get a value from a set other than by enumeration? here in dicts, for example, this can be done by key, but in sets only for tatata in set and then only compare with whatever you want, and do what you want, but there are a lot of such sets and each time you can cut the comparison construction with a value, you can go crazy. How would it be more compact to extract everything from there?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
andymitrich, 2014-05-03
@nextel

Strictly speaking, the set does not maintain the order of the elements - they are stored there, as it were, in a bag: put your hand in - which element comes across, and pull it out. As already mentioned, sets are more suitable for the operation of checking the presence of such an element in the set. If you need direct access to an element, store them in dictionaries or lists.

S
Sergey, 2014-05-03
Protko @Fesor

It's not clear what you want to extract from the set. Sets are needed to check whether values ​​are included there or not. Checks can be written like this (if memory serves):if x in my_set:

N
nivs, 2014-05-03
@nivs

The question is not clear. In sense to pull out value? dict is a mapping (two-dimensional), set is a set (one-dimensional), 2 fundamentally different data structures.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question