Nested Loops

suits = ["❤︎","♦"]
faces = ['Jack', 'Queen', 'King']

cards = list()
for suit in suits:
    cards.append(faces[0] + ' of ' + suit)
    cards.append(faces[1] + ' of ' + suit)
    cards.append(faces[2] + ' of ' + suit)
cards
['Jack of ❤︎',
 'Queen of ❤︎',
 'King of ❤︎',
 'Jack of ♦',
 'Queen of ♦',
 'King of ♦']
suits = ["❤︎","♦︎"]
faces = ['Jack', 'Queen', 'King']

cards = list()
for suit in suits:
    for face in faces: 
        cards.append(face + ' of ' + suit)
cards
['Jack of ❤︎',
 'Queen of ❤︎',
 'King of ❤︎',
 'Jack of ♦︎',
 'Queen of ♦︎',
 'King of ♦︎']
404 image
404 image
404 image
404 image
404 image
404 image
404 image
404 image
404 image
404 image
404 image
cards = list()
for suit in suits:
    print(suit)
    for face in faces: 
        print(face)
        cards.append(face + ' of ' + suit)
cards
❤︎
Jack
Queen
King
♦
Jack
Queen
King
['Jack of ❤︎', 'Queen of ❤︎', 'King of ❤︎', 'Jack of ♦', 'Queen of ♦', 'King of ♦']
404 image

Let’s apply what we learned!