Can I have a loop in a loop as alternative to this question?


#1

for each student in your students list, print out that student’s data, as follows:

print the student’s name
print the student’s homework
print the student’s quizzes
print the student’s tests

For this question I want to use a loop in another loop to solve this question, but I need some help from the community, here is my work:

for x in students:
    for y in x:
        print x[y]

However it has some logic mistakes. Please give me some advice to modify my work,thanks!


#2

Dictionaries are unordered, so now you have no guarantees over the order in which the keys are printed

Your code does pass the exercise for me


#3

Exactly,my results are printed without order.may I ask is there anyway to modify it so that loop in a loop works for this case, as I feel print everything is not so realistic in real life situation.


#4

python has an ordered dictionary in collections, but you would have to consider the pros and cons of using it


#5

Gonna have to define the order somewhere, may as well be in the place where you care about it - the place where you print.


#6

Ok I got the idea,thanks bro.


#7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.