Question

In: Computer Science

This program is about list comprehension. list1 = [2, 5, 7, 8] list2 = [1, 2]...

This program is about list comprehension.

list1 = [2, 5, 7, 8]

list2 = [1, 2]

(e) Use nested list comprehension with list1 and list2 as input sequences to generate this list:

[[3, 4], [6, 7], [8, 9], [9, 10]]

Display the list.

The following is the expected output.

Part e: [[3, 4], [6, 7], [8, 9], [9, 10]]

Solutions

Expert Solution

Code:

list1 = [2, 5, 7, 8]
list2 = [1, 2]
l=[]
for i in range(0,len(list1)):
   a=[]
   for j in range(0,len(list2)):
       a.append(list1[i]+list2[j])
   l.append(a)

print(l)
Code in image with explanation:

Output:


Related Solutions

1.Consider the program: .data myArray: .word 1, 2, 3, 4, 5, 6, 7, 8, 9, 10...
1.Consider the program: .data myArray: .word 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 .text la $s0, myArray li $s1, 0 loop: sll $t0, $s1, 2 add $t0, $t0, $s0 lw $s2, 0($t0) lw $s3, 4($t0) add $s2, $s2, $s3 sw $s2, 0($t0) addi $s1, $s1, 1 slti $t1, $s1, 9 bne $t1, $zero, loop .end Explain what does this program do? How is the data bound from the .data segment to the base address register $s0? What...
A = [4, 5, 9] B = [-4, 5, -7] C = [2, -7, -8, 5]...
A = [4, 5, 9] B = [-4, 5, -7] C = [2, -7, -8, 5] D = [1, -9, 5, -3] E = [3, 3, -1] Uz = 1/|z| ^z d(X,Y) = (Rθ) d = diameter R = Radius θ = Theta Find a. Uc b. d (D, C) c. Let P = B + 3E, UP = d. A x B e. 3B x E f. C x D
(a) Illustrate how the list 5, 13, 2, 25, 7, 17, 20, 8, 4 is sorted...
(a) Illustrate how the list 5, 13, 2, 25, 7, 17, 20, 8, 4 is sorted with Mergesort. Count the number of comparisons made. (b) Illustrate how the list 5, 13, 2, 25, 7, 17, 20, 8, 4 is sorted with Heapsort.
(a) Illustrate how the list 5, 13, 2, 25, 7, 17, 20, 8, 4 is sorted...
(a) Illustrate how the list 5, 13, 2, 25, 7, 17, 20, 8, 4 is sorted with Mergesort. Count the number of comparisonsmade. (b) Illustrate how the list 5, 13, 2, 25, 7, 17, 20, 8, 4 is sorted with Heapsort
A = (1 −7 5 0 0 10 8 2 2 4 10 3 −4 8...
A = (1 −7 5 0 0 10 8 2 2 4 10 3 −4 8 −9 6) (1) Count the number of rows that contain negative components. (2) Obtain the inverse of A and count the number of columns that contain even number of positive components. (3) Assign column names (a,b,c,d) to the columns of A. (4) Transform the matrix A into a vector object a by stacking rows. (5) Replace the diagonal components of A with (0,0,2,3). Hint:...
DATA 3 8 2 15 2 2 0 0 4 5 2 7 0 1 5...
DATA 3 8 2 15 2 2 0 0 4 5 2 7 0 1 5 3 0 2 5 4 1 6 9 5 3 1 2 10 6 1 1 2 1 19 6 6 6 7 0 4 1 1 1 0 1 9 2 2 2 1 16 10 10 5 2 3 1 4 4 4 3 6 2 8 5 2 7 1 6 4 0 3 1 1 1 Background: A group of...
From this Sample No A.   B.      1. 7.   4.      2. 8.   5.      3....
From this Sample No A.   B.      1. 7.   4.      2. 8.   5.      3. 9.   3.      4. 5.   6.      5. 7.   2.      6. 6.   4.   Test of hypothesis for difference of two means by using 1. t Test 2. ANOVA Take 5% type 1 error, then compare the results. Show that t² is equal to f.
In a java program: a) Given the following list of numbers: 90 8 7 56 123...
In a java program: a) Given the following list of numbers: 90 8 7 56 123 235 9 1 653 trace the execution for: Selection Sort (only the first 5 steps) MergeSort. (b) Given the following list of numbers: 3 1 4 1 5 9 2 6 5 3 5 trace the execution for quicksort with median-of-three partitioning and a cutoff of 3.
x 2 8 5 9 4 3 9 6 7 8 y 3 6 5 7...
x 2 8 5 9 4 3 9 6 7 8 y 3 6 5 7 9 7 4 6 9 9 -5.48x + 0.17 5.48x + 0.17 -0.17x + 5.48 0.17x + 5.48
Data: 7,-5, -8, 7, 9, 15, 0, 2, 13, 8, 6, -2, 4 (a) Mean= Mode=...
Data: 7,-5, -8, 7, 9, 15, 0, 2, 13, 8, 6, -2, 4 (a) Mean= Mode= median= (b) Variance= Standard deviation= (c) Range= IQR(Interquartilerange)= (d) Mid-Range= Mid-Hinge=
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT