List of numbers less than 45: [10, 20, 30, 40, 5, 33] The sorted list of numbers is: [5, 10, 20, 30, 33, 40, 66, 77, 88, 99] The sorted list of numbers larger than 45: [66, 77, 88, 99] The sorted list of number smaller than 45: [5, 10, 20, 30, 33, 401 The descending sorted list of numbers is: [99, 88, 77, 66, 40, 33, 30, 20, 10, 5] The descending sorted list of numbers larger than 45: [99, 88, 77, 66] The descending sorted list of number smaller than 45: [40, 33, 30, 20, 10, 5]
how do i do the second part see images
Python code:
list1 = [10, 5, 33, 40, 77, 99, 30, 88, 66, 20]
list2 = [item for item in list1 if item < 45]
print('List of numbers less than 45:\n' ,list2)
x = sorted(list1)
print('The sorted list of numbers are:\n' ,x)
list2 = [item for item in list1 if item > 45]
x=sorted(list2)
print('The sorted list of numbers larger than 45:\n' ,x)
list2 = [item for item in list1 if item < 45]
x=sorted(list2)
print('The sorted list of numbers smaller than 45:\n' ,x)
list1.sort(reverse=True)
print('The descending sorted list of numbers is:\n' ,list1)
list2 = [item for item in list1 if item > 45]
list2.sort(reverse=True)
print('The descending sorted list of numbers larger than 45:\n' ,list2)
list2 = [item for item in list1 if item < 45]
list2.sort(reverse=True)
print('The descending sorted list of numbers smaller than 45:\n' ,list2)
Output:
List of numbers less than 45:
[10, 5, 33, 40, 30, 20]
The sorted list of numbers are:
[5, 10, 20, 30, 33, 40, 66, 77, 88, 99]
The sorted list of numbers larger than 45:
[66, 77, 88, 99]
The sorted list of numbers smaller than 45:
[5, 10, 20, 30, 33, 40]
The descending sorted list of numbers is:
[99, 88, 77, 66, 40, 33, 30, 20, 10, 5]
The descending sorted list of numbers larger than 45:
[99, 88, 77, 66]
The descending sorted list of numbers smaller than 45:
[40, 33, 30, 20, 10, 5]
Step by step
Solved in 2 steps with 1 images