1+ # Check if all elements of list are numbers or not
2+ def check_int (l ):
3+ for i in range (0 , len (l ),1 ):
4+ if not l [i ].isnumeric ():
5+ return False
6+ return True
7+
8+ # If it is a numeric list, then count number of odd values
9+ def count_odd (l ):
10+ if check_int (l ):
11+ count = 0
12+ for i in range (0 ,len (l ),1 ):
13+ if int (l [i ]) % 2 != 0 :
14+ count += 1
15+ print ("Count of odd numbers: " , count )
16+
17+ # If list contains all strings, then display largest string in the list
18+ def largest_str (l ):
19+ flag = True
20+ for i in range (0 , len (l ), 1 ):
21+ if type (l [i ]) != str :
22+ flag = False
23+
24+ if flag :
25+ largest = l [0 ]
26+ for i in l :
27+ if len (i ) > len (largest ):
28+ largest = i
29+ print ("Largest string: " , largest )
30+ else :
31+ print ("List does not contain all strings!" )
32+
33+ # Display list in reverse form
34+ def display_reverse (l ):
35+ for i in range (len (l )- 1 , - 1 , - 1 ):
36+ print (l [i ], end = " " )
37+
38+ # Find a specific item in the list
39+ def find_item (item , l ):
40+ for i in range (0 , len (l ), 1 ):
41+ if item == l [i ]:
42+ print ("Item found at index: " , i )
43+ return
44+ print ("Item not found" )
45+
46+ # Remove the specified item in the list
47+ def remove_item (item , l ):
48+ for i in range (0 , len (l ), 1 ):
49+ if item == l [i ]:
50+ l .remove (item )
51+ print ("Item removed" )
52+ return
53+
54+ # Sort the list in descending order
55+ def sort_desc (l ):
56+ return sorted (l , reverse = True )
57+
58+ # Accept two list and find common members in them
59+ def common (l1 , l2 ):
60+ common = []
61+ for i in range (0 , len (l1 ), 1 ):
62+ for j in range (0 , len (l2 ), 1 ):
63+ if l1 [i ] == l2 [j ]:
64+ common .append (l1 [i ])
65+ if common :
66+ print ("Common elements: " , common )
67+ else :
68+ print ("No common element" )
69+ return
70+
71+ if __name__ == "__main__" :
72+ l = []
73+ n = int (input ("Enter the size of list: " ))
74+ for i in range (0 , n ,1 ):
75+ l .append (input ("Enter element: " ))
76+
77+ if check_int (l ):
78+ print ("All elements are numbers" )
79+ else :
80+ print ("All elements are not numbers" )
81+
82+ count_odd (l )
83+
84+ largest_str (l )
85+
86+ print ("Reversed list:" , end = " " )
87+ display_reverse (l )
88+
89+ item = input ("\n Enter an element: " )
90+ find_item (item ,l )
91+
92+ remove_item (item , l )
93+
94+ print ("Sorted in Descending Order: " )
95+ print (sort_desc (l ))
96+ l2 = []
97+ n = int (input ("Enter the size of new list: " ))
98+ for i in range (0 , n , 1 ):
99+ l2 .append (input ("Enter element: " ))
100+
101+ common (l , l2 )
102+
0 commit comments