Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This problem tests your understanding of list comprehensions. Create a file named Lab 0 6 P 3 . py . Write a Python program that

This problem tests your understanding of list comprehensions.
Create a file named Lab06P3.py. Write a Python program that performs the following steps. In your program output, make sure to indicate which step is being demonstrated with your output (see sample output):
a) Start your program (after the comment header, inside the main function) with this predefined list:
list1=[4,5,8,2]
list2=[2,5,9]
b) Write a one-line list comprehension that is equivalent to the following code and print list3:
list3=[]
for num in range(6):
list3.append(num *2-3)
c) Write a one-line list comprehension that is equivalent to the following code and print list4:
list4=[]
for i in range(4):
for j in range(5):
if i %2==1 and j %2==0:
list4.append([i, j])
d) Write a one-line list comprehension that is equivalent to the following code and print list5:
list5=[]
for i in list1:
list5.append(i **3)
e) Write a list comprehension with list1 only as an input sequence to generate this list:
[12,15,24,6]
f) Write a list comprehension with both list1 and list2 as input sequences to generate this list:
[7,19,35,9,24,44,15,39,71,3,9,17]
g) Write a list comprehension with both list1 and list2 as input sequences to generate this list:Sample output:
Step b:[-3,-1,1,3,5,7]
Step c: [1,0],[1,2],[1,4],[3,0],[3,2],[3,4]
Step d: 64,125,512,8
Step e: 12,15,24,6
Step f:[7,19,35,9,24,44,15,39,71,3,9,17]
Step g: ['4@2','4@5','4@9','5@2','5@5','5@9','8@2','8@5','8@9','2@2','2@5',
'2e9']
Run this program and take a screenshot with the results. Name the screenshot Lab06P3-ouput.jpg.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems For Advanced Applications 18th International Conference Dasfaa 2013 Wuhan China April 22 25 2013 Proceedings Part 2 Lncs 7826

Authors: Weiyi Meng ,Ling Feng ,Stephane Bressan ,Werner Winiwarter ,Wei Song

2013th Edition

3642374492, 978-3642374494

More Books

Students also viewed these Databases questions

Question

Annoyance about a statement that has been made by somebody

Answered: 1 week ago

Question

love of humour, often as a device to lighten the occasion;

Answered: 1 week ago

Question

orderliness, patience and seeing a task through;

Answered: 1 week ago

Question

well defined status and roles (class distinctions);

Answered: 1 week ago