Created
April 29, 2021 23:19
-
-
Save IvanFrecia/7d8d8990afe992b258ad6872f3e0f4a8 to your computer and use it in GitHub Desktop.
Coursera - Python 3 Programming Specialization - Course 2 - 13.2 Tuple Packing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 2) Create a tuple called practice that has four elements: ‘y’, ‘h’, ‘z’, and ‘x’. | |
# Answer: | |
practice = 'y', 'h', 'z', 'x' | |
print(practice) | |
# 3) Create a tuple named tup1 that has three elements: ‘a’, ‘b’, and ‘c’. | |
# Answer: | |
tup1 = 'a', 'b', 'c' | |
print(tup1) | |
# 4. Provided is a list of tuples. Create another list called t_check that contains the third element | |
# of every tuple. | |
# Answer: | |
lst_tups = [('Articuno', 'Moltres', 'Zaptos'), ('Beedrill', 'Metapod', 'Charizard', 'Venasaur', 'Squirtle'), ('Oddish', 'Poliwag', 'Diglett', 'Bellsprout'), ('Ponyta', "Farfetch'd", "Tauros", 'Dragonite'), ('Hoothoot', 'Chikorita', 'Lanturn', 'Flaaffy', 'Unown', 'Teddiursa', 'Phanpy'), ('Loudred', 'Volbeat', 'Wailord', 'Seviper', 'Sealeo')] | |
t_check = [] | |
for tup in lst_tups: | |
t_check.append(tup[2]) | |
print (t_check) | |
# Below, we have provided a list of tuples. Write a for loop that saves the second element of each tuple into | |
# a list called seconds | |
# Answer: | |
tups = [('a', 'b', 'c'), (8, 7, 6, 5), ('blue', 'green', 'yellow', 'orange', 'red'), (5.6, 9.99, 2.5, 8.2), ('squirrel', 'chipmunk')] | |
seconds = [] | |
for second in tups: | |
seconds.append(second[1]) | |
print(seconds) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment