Coding
Coding
CODE
list1=[1,2,3,4,5,6]
print(list1[::-1])
print(list1[::2])
print(list1[1::2])
OUTPUT
[6, 5, 4, 3, 2, 1]
[1, 3, 5]
[2, 4, 6]
1-b--------------------------------------------------------
# Create a list of integers
print("Accessing elements:")
print("\nReplacing elements:")
my_list[1] = 25
print("\nInserting elements:")
my_list.insert(3, 35)
print("\nDeleting elements:")
del my_list[4]
my_list.remove(30)
OUTPUT
Accessing elements:
Element at index 2: 30
Replacing elements:
Inserting elements:
Deleting elements:
1-C----------------------------------------------------------------------------------------------------------------
my_list = []
my_list.append(50)
my_list.append(30)
my_list.append(10)
my_list.append(40)
my_list.append(20)
# Display the original list
my_list.sort()
search_element = 30
if search_element in my_list:
else:
OUTPUT
1-d----------------------------------------------------------------------------------------------------------------
list1= [1,2,3,1,4,2,5,3,6]
list2= [ ]
for i in (list1):
if i not in(list2):
list2.append(i)
print(list2)
OUTPUT
[1, 2, 3, 4, 5, 6]
I-e----------------------------------_______________________________________________
32, 2, 3, 5, 6]
E,To count the no. of times an element occurs in a
list.
code
list1=[]
n=int(input("range"))
for i in range(n):
list1.append(int(input()))
o=int(input("enter the element to check occurence"))
c=0
for i in range (len(list1)):
if o==list1[i]:
c+=1
print(o,"occured",c,"times")
OUTPUT
range10
1
1
1
1
1
2
1
31
1
2
enter the element to check occurence1
1 occured 7 times
1-
f-------------------------------------------------------------------------------------------------------------------
-