Review Python Lists (Exercises)
00:00
And let’s sneak in a bit more practice before you finish up with the course. Create a tuple called data
with two values. The first value should be the tuple (1, 2)
, and the second value should be the tuple (3, 4)
.
00:13
Then write a for
loop that loops over data
and prints the sum of each nested tuple. The outputs should look like shown below. So it should say Row 1 sum: 3
, and then Row 2 sum: 7
.
00:30
There’s a bit more. Create the list that contains the integers [4, 3, 2, 1]
, and then assign it to the variable numbers
. Then create a copy of the numbers
list using the slice notation with [:]
.
00:45
And finally, sort the numbers
list in numerical order using the .sort()
method. So just a couple more review exercises to strengthen your learning.
Syed on Feb. 17, 2024
Hello Martin,
I have same question as Ivan**
Martin Breuss RP Team on Feb. 19, 2024
Hi @Ivan Mladenovity and @Syed, you can use enumerate()
, but you don’t have to.
You can check out some possible solutions in the related lesson on Tuple Sums in the Tuples and Lists Exercises Course.
Become a Member to join the conversation.
Ivan Mladenovity on Feb. 3, 2024
Hello Martin! Are we using enumerate here in for loop for Row 1 and Row 2?