Question On List Comprehension
Question On List Comprehension
2 - Get the first element from each nested list in a list | li = [[1,2,3],[4,5,6],
[7,8,9],[10,11,12],[13,14,15]]
Use list comprehension to extract the first element of each nested list
a=[1,2,3,4,5,6,7,8,9,10]
Expected output :
a=[1,2,3,4,5,6,7,8,9,10]
Expected output :
['number is odd : 1', 'number is even : 2', 'number is odd : 3', 'number is even :
4', 'number is odd : 5', 'number is even : 6', 'number is odd : 7', 'number is even
: 8', 'number is odd : 9', 'number is even : 10']
original_list = [2,3.84,0.04,8,9]
original_list = [2,3.84,0.04,8,9]
9 - "Write a Python program to filter out strings from a list 'l' that contain only
alphabetic characters and don't start with a special character or a number.
11 - Given a list of numbers, remove all odd numbers from the list:
numbers = [3,5,45,97,32,22,10,19,39,43]
12 - v = [2,3,4]
s = -3
Expected output : [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]
languages = ['java','python','php','c','javascript']
basket = ['apple','guava','cherry','banana']
my_fruits = ['apple','kiwi','grapes','banana']
a = "hello world"
Expected output : ['h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd']
li = [1,2,3,4,5,6,7,8,9,10]
22 - generate a new list that contains the lengths of each fruit's name.
23 - Use list comprehension to create a new list, and then determine and print the
length of the new list.
Expected output : 4
24 - make a list that contains each fruit with more than 5 characters
27 - Make a variable named even_numbers that holds only the even numbers
numbers = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 17, 19, 23, 256, -8, -4, -2, 5, -9]
28 - Make a variable named odd_numbers that holds only the odd numbers
numbers = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 17, 19, 23, 256, -8, -4, -2, 5, -9]
30 - mtlist =['101','102','103','515','117']
find those number whose first and last elements are same
Expected output : ['Hello world', 'Hello bdit', 'class world', 'class bdit']
Expected output : [3, 13, 23, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 43, 53, 63,
73, 83, 93]
Expected output : ['even', 'odd', 'even', 'odd', 'even', 'odd', 'even', 'odd',
'even', 'odd']
Expected output : 7
38 - Remove vowel
w="hello"