Python : Can you explain me the working of set iteration ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Python : Can you explain me the working of set iteration ?

As Set is unindexed , how set checks if an item is present? How SET iterates through elements if it doesnt have index? Can you explain me what happens inside the working of iteration of Sets ?

11th Jan 2020, 3:54 AM
Sri Lakshmi
Sri Lakshmi - avatar
8 Answers
+ 2
Thanks Gordon ... But I would like to clarify about working of set iteration that happens inside computer... As list uses index to iterate through elements , How does set iterate through elements without index ?
11th Jan 2020, 4:20 AM
Sri Lakshmi
Sri Lakshmi - avatar
+ 2
Set is unordered.
11th Jan 2020, 6:34 AM
Gordon
Gordon - avatar
+ 2
Here are 6 other ways to iterate over set https://www.google.com/amp/s/www.geeksforgeeks.org/iterate-over-a-set-in-JUMP_LINK__&&__python__&&__JUMP_LINK/amp/ In terms of efficiency, simple is best.
11th Jan 2020, 6:50 AM
Gordon
Gordon - avatar
+ 1
A set is used to know whether an object is in or not : it is not used to behave in the same way of a list. A set is iterable because Python widely use iterable object : it is the only way to access to a set.
11th Jan 2020, 6:03 AM
Théophile
Théophile - avatar
+ 1
Thanks Théophile
11th Jan 2020, 6:37 AM
Sri Lakshmi
Sri Lakshmi - avatar
+ 1
Thanks Gordon
11th Jan 2020, 6:37 AM
Sri Lakshmi
Sri Lakshmi - avatar
+ 1
Thank you very much Gordon
11th Jan 2020, 7:08 AM
Sri Lakshmi
Sri Lakshmi - avatar