by CodeChum Admin
Did you know that you can also reverse lists and group them according to your liking with proper code? Let's try it to believe it.
Instructions:
Input
The first line contains an odd positive integer.
The next lines contains an integer.
5
1
3
4
5
2
Output
A line containing a list.
[2,5]-[4]-[3,1]
import random
n = int(input('Enter odd integer here: '))
list1 = [random.randint(0,30) for x in range(n)]
list2 = list1[::-1]
print([list2[:(n//2)], list2[(n//2)], list2[(n//2+1):]])
Enter odd integer here: 5
[[4, 20], 19, [18, 4]]
Comments
Leave a comment