Answer to Question #259152 in Java | JSP | JSF for joy

Question #259152

8. Groupings



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:




Create a variable that accepts a positive odd integer.



Create an empty list. Then, using loops, add random integer values into the list one by one. The number of values to be stored is dependent on the inputted odd integer on the first instruction.



Reverse the order of the list. Then, print out the list's new order in this manner:



[first-half values]-[middle value]-[second-half values], just like that of the sample output. Make use of list slicing that you’ve learned from the past lessons to easily achieve this segment.



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]

1
Expert's answer
2021-11-03T11:44:34-0400
n = int(input('Enter odd integer here: '))
list1 = []
for ​i in range(n):
​list1.append(input('Enter no here: '))
print(list1[:(n//2)], '-', list(list1[(n//2)]), '-', list1[((n//2)+1):]

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS