Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access to the values of set()

Tags:

python

Any way to access the values of BIF "set()" without using an iterator.

For instance, I got this output from my code:

>>> set([1,2,3]) 

How can I access it as a list? Like:

>>> [1,2,3]
like image 419
Fish Avatar asked Mar 15 '11 10:03

Fish


People also ask

How do you access values stored in a set?

You cannot access items in a set by referring to an index or a key. But you can loop through the set items using a for loop, or ask if a specified value is present in a set, by using the in keyword.

What is set () in Python?

The set() function creates a set object. The items in a set list are unordered, so it will appear in random order. Read more about sets in the chapter Python Sets.

How do I get an element from a set in Python?

To retrieve all elements from a set, you can use a simple for-loop. Another approach is to create an iterator object and retrieve the items from it using the next() function. The next() function raises StopIteration when the iterator is exhausted.

How do you get a set value in darts?

To do, so we make use of toList() method in Dart. List<type> list_variable_name = set_variable_name. toList(); Note: It is useful in the way as the list we will get will contain unique values and no repeated values.


2 Answers

Use a simple type conversion:

>>> a
set([1, 2, 3])
>>> list(a)
[1, 2, 3]
like image 199
utdemir Avatar answered Oct 04 '22 16:10

utdemir


Make a list, like

list(set([1, 2, 3]))
like image 34
eat Avatar answered Oct 04 '22 18:10

eat