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]
from random import randint
odd = int(input('Enter odd integer: '))
L = list()
for _ in range(odd):
L.append(str(randint(1, 9)))
L = L[::-1]
half = odd//2
print('[' + ','.join(L[:half]) + ']-[' + L[half] + ']-[' + ','.join(L[half+1:]) + ']')
Comments
Leave a comment