11 List Programs
11 List Programs
#list of numbers
list1 [10, 20, 4, 45, 99]
#list of numbers
listi [10, 20, 4, 45, 99]
# list of numbers
listi [10, 20, 4, 45, 99]
# sorting the list
list1.sort()
# printing the first element
print("Smallest element is:", *list1[:1])
Smallest element is: 4
In
[5]:4 number in a list
#list of numbers
listi [10, 20, 1, 45, 99]
# Swapping
temp newList[0]
newList [0] =
newlist [size - 1]
newList[size 1J = temp
return newlist
#Driver code
newList [12, 35, 9, 56, 24]
print (swapList (newList))
[24, 35, 9, 56, 12]
n tist in Python and provided
17 #oiven a
# Python3 program to swap elements
the positions of the elements, write a
program
# at given positions
# Swap function
def swapPositions(list, pos1, pos2):
# Driver function
List [23, 65, 19, 90]
pos1, pos2 = 1, 3
In [8]:
The list is : [1, 4, 5, 7, 8]
5
Length of list using naive method is:
# creating a list
list1 =
[11, 5, 17, 18, 23]
# Iterate each element in list
# and add them in variable total
for ele in range(0, len(1ist1)):
total total 1ist1[ele]
return result
# Driver code
list1 [1, 2, 3]
list2 = [3, 2, 4]
24
# Initializing list
test_list =
[5, 6, [1, 3, [], [, 9]
# printing original list
# printing resultt
print ("List after empty list removal "* str(res))
z [x for x in sorted(zipped_pairs)]
return z
driver code
"f", "g", "h", "i"]
x ["a", "b", "c", "d",
2
2, , 1]
y = [ 0, 1, 1, , 1