Difference between revisions of "CSC111 List Comprehension Exercises"

From dftwiki3
Jump to: navigation, search
(Created page with "--~~~~ ---- <br /> <br /> <source lang="python"> L = [ ("a", 1), ("b", 3), ("c", -1), ("d", 0.001) ] </source> <br /> Answer the following questions regarding the list L abov...")
 
 
Line 27: Line 27:
 
: Generate a list L7 of the pairs in L and make the name upper-case.
 
: Generate a list L7 of the pairs in L and make the name upper-case.
 
<br />
 
<br />
Question 7
+
;Question 7
 
: Generate a list L8 of the pairs in L where the number is the absolute value of the numbers in L.
 
: Generate a list L8 of the pairs in L where the number is the absolute value of the numbers in L.
 
<br />
 
<br />

Latest revision as of 09:06, 28 March 2014

--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.