Python Programming (2019FA.CSC.121.2801) Lesson 06

Ace your homework & exams now with Quizwiz!

What is the output of the following Python program? tuple1 = (2, 5, 3, 6) tuple1.insert(2, 7) print(tuple1)

. None of the above

What is the output of the following Python program? list1 = [[2, 7, 1], [8, 5, 6]] print(list1[1]) print(list1[1][1])

. [8, 5, 6] 5

What is the output of the following Python program? xy_tups = [] for x in ['m', 't', 'b']: for y in ['b', 't', 'e']: if x <= y: xy_tups.append ((x, y)) print(xy_tups)

[('m', 't'), ('t', 't'), ('b', 'b'), ('b', 't'), ('b', 'e')]

What is the output of the following Python program? list1 = [2, 3, 4] list2 = [1, 5] list3 = [0] list3 = list2 + list1 print(list3)

[1, 5, 2, 3, 4]

What is the output of the following Python program? list1 = [2, 3, 4] list3 = [0] list3 = list1[1:] print(list3)

[3, 4]

list1 = [[2, 7, 1], [8, 5, 6]] Which of the following code fragments generates this output: 2 7 1 8 5 6

for r in range(2): for c in range(3): print(list1[r][c])

Rewrite the following code with list comprehension: list1 = [4, 7, 12, 8, 25] list2 = [] for x in list1: if x > 10: list2.append(x*2)

list1 = [4, 7, 12, 8, 25] list2 = [x*2 for x in list1 if x > 10]

Which of the following Python programs generates the list [0, 1, 2]?

list1 = [] for num in range(3): list1 = list1 + [num]

Given the following list comprehension, write the equivalent code without using list comprehension: list1 =[[x,y] for x in range(3) for y in range(2) if (x + y) % 2 == 0]

list1 = [] for x in range(3): for y in range(2): if (x + y ) % 2 == 0: list1.append([x,y])

list1 = [1, 2, 3] list2 = ['A', 'B'] Which of the following list comprehensions creates the following output list? [[(1,'A'),(1,'B')], [(2,'A'),(2,'B')], [(3,'A'),(3,'B')]]

output_list = [[(x,y) for y in list2] for x in list1]


Related study sets

COMPTIA A+ 220-1102 Malware Detection, Removal, & Prevention

View Set

50 Question Wonderlic Practice Test

View Set

AEID 1445 Unit 4 : Extension Lines and Dimension Lines

View Set

Agarose Gel Electrophoresis Lab quiz

View Set

Biology 1 - 02.04 Cell Structure and Function

View Set

Evolve EAQ: Psych - Psych/HM Drugs

View Set