CSC111 List Comprehension Exercises
--D. Thiebaut (talk) 10:05, 28 March 2014 (EDT)
L = [ ("a", 1), ("b", 3), ("c", -1), ("d", 0.001) ]
Answer the following questions regarding the list L above in Python.
- Question 1
- Generate a list L2 of just the numbers in L.
- Question 2
- Generate a list L3 of just the names in L.
- Question 3
- Generate a list L4 of the pairs in L where the pairs have the number first and the name second.
- Question 4
- Generate a list L5 of just the numbers in L that are positive (>0).
- Question 5
- Generate a list L6 of just the pairs in L that have a number that is positive.
- Question 6
- Generate a list L7 of the pairs in L and make the name upper-case.
- Question 7
- Generate a list L8 of the pairs in L where the number is the absolute value of the numbers in L.