0% found this document useful (0 votes)
4 views3 pages

Tasks

The document contains a series of programming exercises involving list, dictionary, and set comprehensions in Python. It includes tasks such as creating lists of squares, extracting numbers, and mapping words to their lengths. Additionally, it mentions a video class on Arbitrary Arguments that needs to be watched and documented for a future class.

Uploaded by

bragha144
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Tasks

The document contains a series of programming exercises involving list, dictionary, and set comprehensions in Python. It includes tasks such as creating lists of squares, extracting numbers, and mapping words to their lengths. Additionally, it mentions a video class on Arbitrary Arguments that needs to be watched and documented for a future class.

Uploaded by

bragha144
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

‭ .

‬ C
1 ‭ reate a list of squares of all even numbers from 1 to 20.‬
"Python is‬
‭2.‬ ‭Create a list of the lengths of each word in a given sentence‬‭
awesome and fun"‬
‭ ‭.‬
[2, 3, 5, 7, 10,‬
‭3.‬ ‭Extract all numbers greater than 5 from a given list‬‭
‭, 4, 8]‬
1 ‭.‬
‭ .‬ ‭Create a list containing only the first character of each word in a given list‬
4
["apple", "banana", "cherry", "date"]‬
‭ ‭.‬
‭5.‬ ‭Create a list of tuples with the number and its square for numbers from 1‬
‭to 10.‬
‭6.‬ ‭Create a list of strings that are uppercase and have more than 3 letters‬
['abc', 'DEF', 'ghi', 'JKL', 'mnop']‬
‭from the list‬‭ ‭.‬
‭7.‬ F ‭ latten a 2D list‬‭[[1, 2], [3, 4], [5, 6]]‬‭into a‬‭single list.‬
‭Out_put : [1,2,3,4,5,6]‬
‭8.‬ ‭Given a list of numbers‬‭ [1, 2, 3, 4, 5]‬ ‭, generate‬‭a new list where each‬
‭element is the result of multiplying the original number by 3, but only if‬
‭the number is odd.‬
‭9.‬ ‭Using a nested ternary operator, create a list that replaces numbers greater‬
'Large'‬‭and others with‬‭
‭than 10 with the string‬‭ 'Small'‬‭from the list‬‭
[5,‬
12, 9, 19, 7, 3]‬
‭ ‭.‬
‭Dictionary Comprehension Questions‬

‭1.‬ C ‭ reate a dictionary where keys are numbers from 1 to 5 and values are their‬
‭squares.‬
‭2.‬ ‭Given a list of names‬‭ ['Alice', 'Bob', 'Charlie']‬ ‭,‬‭create a dictionary‬
‭where each name is a key, and the value is the length of the name.‬
‭3.‬ ‭Create a dictionary where the keys are the numbers from 1 to 10 and the‬
'Even'‬‭or‬‭
‭values are‬‭ 'Odd'‬‭based on whether the number‬‭is even or odd.‬
‭4.‬ G [(1, 'a'), (2, 'b'), (3, 'c')]‬
‭ iven a list of tuples‬‭ ‭,‬‭create a‬
‭dictionary where the first element of each tuple is the key and the second‬
‭element is the value.‬
‭5.‬ ‭Create a dictionary that maps the first letter of each word to the‬
["apple", "banana",‬‭
‭corresponding word from the list‬‭ "cherry",‬
"date"]‬
‭ ‭.‬
‭6.‬ C ['apple', 'banana',‬‭
‭ reate a dictionary from a list‬‭ 'cherry', 'date']‬
‭where the key is the word and the value is its length, but exclude words with‬
‭less than 5 letters.‬
{'a': 1,‬
‭7.‬ ‭Using a dictionary comprehension, invert the following dictionary‬‭
'b': 2, 'c': 3}‬
‭ ‭, so the values become keys and keys‬‭become values.‬
‭8.‬ C ‭ reate a dictionary that maps each word in the sentence‬‭"This is Python"‬
‭to its index in the sentence.‬
['apple',‬
‭9.‬ ‭Create a dictionary where keys are the elements of a list‬‭
'banana', 'cherry', 'date']‬‭and values are‬‭
‭ 'Yes'‬‭if‬‭the word contains‬
'No'‬‭otherwise.‬
‭more than 5 letters,‬‭

‭Set Comprehension Questions‬

‭ .‬ C
1 ‭ reate a set containing all even numbers between 1 and 20‬
"Python Programming"‬
‭2.‬ ‭Create a set of the unique characters in the string‬‭ ‭.‬
‭3.‬ F [1, 2, 2, 3, 4, 5, 5, 6]‬
‭ rom a list of numbers‬‭ ‭, create‬‭a set of unique‬
‭numbers.‬
‭4.‬ ‭Create a set that contains only the vowels from the string‬‭ "The quick brown‬
‭ox jumps over the lazy dog"‬
f ‭.‬
‭ .‬ ‭Create a set of squares for all numbers from 1 to 10, but only include the‬
5
‭square if it’s an odd number.‬

‭27/12/2024‬

‭1.‬ ‭String methods without using string methods using functions and‬
‭return s‬ ‭statements.‬

‭2.‬ ‭Complete the following pattern programming using functions and‬


‭appropriate arguments.‬
‭3.‬ ‭We have uploaded the video class on‬‭Arbitrary Arguments‬‭with the title‬‭28th‬
December - Arbitrary Arguments‬‭All of you've to watch‬‭the video, document it with‬

‭proper code and be prepared for the class on Monday at all costs.‬

You might also like