Python list function tutorial
list1 = [10, 20, 4, 45, 99] mx=max(list1[0],list1[1]) secondmax=min(list1[0],list1[1]) n =len(list1) for i in range(2,n): if list1[i]>mx: secondmax=mx mx=list1[i] elif list1[i]>secondmax and \ mx != list1[i]: secondmax=list1[i] print("Second highest number is : ",\ str(secondmax)) Output:- Second highest number is : 45
Source: www.codeexampler.com
python list example
List = [1, 2, 3, "GFG", 2.3] print(List)
Source: www.geeksforgeeks.org
list example in python
# list of numbers n_list = [1, 2, 3, 4] # 1. adding item at the desired location # adding element 100 at the fourth location n_list.insert(3, 100) # list: [1, 2, 3, 100, 4] print(n_list) # 2. adding element at the end of the list n_list.append(99) # list: [1, 2, 3, 100, 4, 99] print(n_list) # 3. adding several elements at the end of list # the following statement can also be written like this: # n_list + [11, 22] n_list.extend([11, 22]) # list: [1, 2, 3, 100, 4, 99, 11, 22] print(n_list)
Source: beginnersbook.com