Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to Code List Comprehension Python-Best Example

How To Code List Comprehension Python-Best Example

Write a program to generate two lists using list Comprehension. One list should contain first 20 Odd Numbers and another should contain first 20 even numbers.Programlst1 = [x for x in range(40) if x % 2 != 0] print('First 20 Odd Numbers:') print(lst1) lst2 = [x for x in range(40) if x % 2 == 0] print('First 20 Even Numbers:') print(lst2)The OutputFirst 20 Odd Numbers: [1, 3, 5, 7, 9, 11, 13, 15,



This post first appeared on ApplyBigAnalytics, please read the originial post: here

Share the post

How to Code List Comprehension Python-Best Example

×

Subscribe to Applybiganalytics

Get updates delivered right to your inbox!

Thank you for your subscription

×