-1
student_name = {"Karrie", "Freya", "Bruno"}

for name in student_name:
print("The student name is {0}".format(name))

I am trying to run this loop but the order the result is in this form

The student name is Freya
The student name is Karrie
The student name is Bruno
Nischit
  • 89
  • 1
  • 8
  • 3
    **set** is unordered like **dictionary**. Use **list** / **tuple** based on requirements.. – hygull Jun 21 '18 at 08:27

2 Answers2

0

Sets are unordered. If you're looking for an ordered collection, use a list:

student_name = ["Karrie", "Freya", "Bruno"]

for name in student_name:
    print("The student name is {0}".format(name))
L3viathan
  • 26,748
  • 2
  • 58
  • 81
0

Use sorted:

student_name = {"Karrie", "Freya", "Bruno"}
for name in sorted(student_name):
    print("The student name is {0}".format(name))
Alexander
  • 51
  • 8