27
loading...
This website collects cookies to deliver better user experience
L = [123,'abc',[99,100],1.38]
Print(L[2][1])
Average = sum(L)/len(L)
List_1 = eval(input(‘Enter a list’))
Print(‘The first element is : ‘, L[0])
tuple_a =('abc',456,3.14,'mary')
list(tuple_a)
['abc', 456, 3.14, 'mary']
set_a = {1,'efg',9.8}
list(set_a)
[1, 'efg', 9.8]
# Create the dictionary d
d = {'A':404, 'B':911}
# Generates the keys of d
list(d)
# Generate values
list(d.values())
# Generate items – key – value pairs
list(d.items())
['A', 'B']
[404, 911]
[('A', 404), ('B', 911)]
newlist = [expression for item in iterable if condition == True]
L = [i for i in range(5)]
Print(L)
[0,1,2,3,4]
[0 for i in range(10)]
[0,0,0,0,0,0,0,0,0,0]
[i**2 for i in range(1,8)]
[1,4,9,16,25,36,49]
L = [2,4,9,4,61]
[i*10 for i in L]
[20, 40, 90, 40, 610]
string = 'Hello World'
[c*2 for c in string]
['HH', 'ee', 'll', 'll', 'oo', ' ', 'WW', 'oo', 'rr', 'll', 'dd']
w = ['one', 'two', 'three', 'four', 'five', 'six']
[m[0] for m in w]
['n', 'w', 'h', 'o', 'i', 'i']
L = [2,4,9,4,61]
[i for i in L if i>5]
[9, 61]
w = ['one', 'two', 'three', 'four', 'five', 'six']
[m[1] for m in w if len(m)==3]
['n', 'w', 'i']