Access Set Items
Read a set by membership or iteration, not by numeric position. Its interface is designed around inclusion rather than an ordered row number.
Understand the idea
The in operation asks whether an equal element is present. Looping visits each element once, but do not depend on that order across runs or versions. A sorted list gives a deliberate output order while leaving the underlying set available for membership checks.
Where to try it
Open this example with Try in playground. The code loads as editable text and does not run until you select Run. The first run downloads Python. Each run starts fresh; temporary files created by a script are not files on your PC.
A worked example
allowed = {"html", "css", "python"}
print("sql" in allowed)
for name in sorted(allowed):
print(name)
Read the result
Membership is False, followed by css, html, and python in explicit sorted order.
Try one change
Validate a requested course name against the set and show a clear message when it is unsupported.