The Python list Sort() method is used to sort lists. This function outputs a sorted() list of values from a list of inputs.
Python List Sort () Example:
Learn how to sort() a list in python,how to convert string to list in python programs and how to append to a list in python.
These are the simple python programs for sorting () lists We have listed some complex python programs to sort() lists and their solutions in which you will learn how to sort() a list in python and how to convert string to list in python and also how to append to a list in python.
Python List Sort() :
Python programs to sort() list and answers:
Q1:
Suppose you have a list [ [1,2,3,4,5 ], ['Burger', 'Sandwitch', 'Pizza',
'Chiken Roll', 'Kabab' ] ], access each individual element from the
list and dispary as menu.
e.g.
1. Burger
Solution:
lst = [[1,2,3,4,5 ],['Burger', 'Sandwitch', 'Pizza','Chiken Roll', 'Kabab' ]]
for i in range(len(lst[0])):
print(lst[0][i],lst[1][i])
Q2:
Suppose
you have a list [ ['Biryani', 'Korma', 'Karahi', 'Nihari', 'Payen' ],
['Burger', 'Sandwich', 'Pizza', 'Chicken Roll', 'Kabab' ] ], access each
individual element from the list and display as menu. e.g.
1. Biryani
2. Korma
Solution:
lst = [['Biryani', 'Korma', 'Karahi', 'Nihari', 'Payen' ],
['Burger', 'Sandwich', 'Pizza', 'Chicken Roll', 'Kabab']
]
sn = 1
for i in range(len(lst)):
for j in lst[i]:
print(sn, j)
sn += 1
Q3: Write a Program that print the right-triangle of (a) Symbol such as *, (b) Number
e.g:
(a) * (b) 1
* * 2 2
* * * 3 3 3
* * * * 4 4 4 4
Solution (a) :
for i in range(4):
for j in range(i+1):
print('*',end='')
print('')
Solution (b) :
for i in range(4):
for j in range(i+1):
print(i+1,end='')
print('')
Q4:
Re-write Q3 program, as the program starts (executed) it should take
the user input as the height of the triangle. and print N height
triangle
Solution:
a = int(input("Enter the height of triangle: "))
for i in range(a):
for j in range(i+1):
print(i+1,end='')
print('')
0 Comments