List_Worksheet practice
List_Worksheet practice
list1=[1, 3, 2]
list1 * 2
l="Welcome to Python".split()
l
a=[[[1,2],[3,4],5],[6,7]]
a[0][1][1]
a,b=[3,1,2],[5,4,6]
a+b
a=[2,1,3,5,2,4]
a.remove(2)
a
odd = [1, 9]
odd.insert(1,3)
print(odd)
odd[2:2] = [5, 7]
print(odd)
odd = [1, 3, 5]
print(odd + [9, 7, 5])
print(["re"] * 3)
odd = [2, 4, 6, 8]
odd[0] = 1
print(odd)
odd[1:4] = [3, 5, 7]
print(odd)
l=[10,20,30,40,50,60]
for i in range(1,6):
l[i-1]=l[i]
for i in range(0,6):
print(l[i],end='')
l=[6,12,18,24,30]
for i in l:
for j in range(1,i%5):
print(j,'#',end='')
print()
"Welcome to Python4csip.com".split()
myList = [1, 5, 5, 5, 5, 1]
max = myList[0]
indexOfMax = 0
for i in range(1, len(myList)):
if myList[i] > max:
max = myList[i]
indexOfMax = i
print(indexOfMax)
list("a#b#c#d".split('#'))
a="hello"
b=list((x.upper(),len(x)) for x in a)
print(b)
a=[[]]*3
a[1].append(7)
print(a)
L1 = list()
L1.append([1, [2, 3], 4])
L1.extend([7, 8, 9])
print(L1[0][1][1] + L1[2])
T = [1, 2, 3, 4, 5, 6, 7, 8]
print(T[T.index(5)], end = " ")
print(T[T[T[6]-2]-4])
l = [None] * 10
print(len(l))
resList = [x+y for x in ['Hello ', 'Good '] for y in ['Dear', 'Bye']]
print(resList)
A = [2, 4, 6, 8, 10]
L = len(A)
S = 0
for I in range(1, L, 2):
S+=A[I]
print("Sum=", S)
38. Given a Python list, find value 20 in the list, and if it is present, replace it with 200.
Only update the first occurrence of a value
41. Write a Python program to get the largest number from a list.
42. Write a Python program to count the number of strings where the string length
is 2 or more and the first and last character are same from a given list of
strings.
Expected Result : 2 .
45. Take a list of 10 elements. Split it into middle and store the elements in two
different lists.