Skip to main content

9.11) Exercise 24 - List Comprehension


  1. Using a list comprehension, add the two columns from each row of the matrix M together:
M=[[1,9],[2,8],[3,7]]
# Result is: [10, 10, 10]

Solution 1

  1. Use a list comprehension to produce the result (as a list) of a roll of three dice

Hint: Use the randint function from the random module to get a random integer.
Hint: You can use the sequence over which you are looping only as a way of counting.
Solution 2