Home python Task "Rearrange Min and Max"

Task “Rearrange Min and Max” [Duplicate]




In the list, all elements are different. Change places the minimum and maximum item of this list.

a = [int (i) for i in input (). Split ()]
A [A.INDEX (MAX (A)]], A [A.INDEX (MIN (A))] = A [A.INDEX (MIN (A)]], A [A.INDEX (MAX (A)) ]
Print ('' .join ([STR (I) for i in a]))

In some examples, the program works, in others it simply issues the original list. For example: on the 3 4 5 list, 1 does not work, and on the 1 5 4 3 list works.

Answer 1, Authority 100%

a little rewrote your code, but the meaning is the same:

a = [int (i) for i in input (). Split ()]
min_index = a.index (MIN (A))
max_index = A.INDEX (MAX (A))
[a [max_index], a [min_index]] = [A [MIN_INDEX], A [MAX_INDEX]]
Print ('' .join ([STR (I) for i in a]))
Previous articleHow to convert char in INT?
Next articleConnect OJDBC

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions