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


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!


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


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.


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


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


Ok I got the idea,thanks bro.


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