v Unpacking A Tuple - Python

Unpacking A Tuple

Interesting in learning more? Check out Fluent Python

Create List Of Tuples

# Create a list of tuples where the first and second element of each 
# super is the first last names, respectively
soldiers = [('Steve', 'Miller'), ('Stacy', 'Markov'), ('Sonya', 'Matthews'), ('Sally', 'Mako')]

Unpack Tuples

# For the second element for each tuple in soldiers,
for _, last_name in soldiers:
    # print the second element
    print(last_name)
Miller
Markov
Matthews
Mako