There is a function that makes up the list of profiles:

def all_players_profile(): l = [] x = main.numb_of_players() n = 0 while n < x: n +=1 l.append(player_profile()) return l 

You need to write a function that, using the result of the function call all_players_profile() , will return a new list in which the profiles will be ordered randomly.

I absolutely do not understand how this can be done.

Closed due to the fact that it was off-topic by the participants Athari , Mirdin , fori1ton , VenZell , Pavel Mayorov 6 May '15 at 8:03 .

  • Most likely, this question does not correspond to the subject of Stack Overflow in Russian, according to the rules described in the certificate .
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Try to clarify with the one who gave the task. Perhaps we mean a list with a random order of elements ... - Vladimir Martyanov
  • @ Vladimir Martianov, as I understand it, yes. in number 10 there will be 4 profiles, and I need to make number 11, which will take the number 10 list and randomly scatter it. - Denis
  • 3
    I vote for closing this question as not relevant, because it is a question: “do it for me” - Mirdin

1 answer 1

Sort an array in random order in Python:

 from random import shuffle shuffle(l) 

In this case, the list itself will be jumbled.

Possible without using shuffle :

 sorted(l, key=lambda *args: random.random()) 

In this case, a new list will be created.

  • Only shuffle does not return a new list, but changes it in place - andreymal
  • @andreymal if not difficult, can you write ready-made code? it’s somehow difficult for me, I don’t understand where to start, what to do and how to finish it :) - Denis
  • 3
    @Denis You honestly tell yourself, do you want to be a programmer or not? If not, why would you learn from it? And if so, write !!! Sloppy, guan-codist, with a rake, but write! Understanding how it will come later! - sys_dev
  • @sys_dev I would really like it, but I just don’t know how. almost the whole day tormented, does not work. and this is for tomorrow. - Denis
  • @Denis Situations in the "must-yesterday" style are very rare! In university, everything is always in advance and it allows you to plan! - sys_dev