mercredi 2 décembre 2015

python how to index a list and then select randomly from it

I have an "initial_list" that contains 100 strings. I'd like initial_list to index using "member". And from "member" I need to select 100 random members of the initial_list then I need to transfer them to a "second_list". My strategy is as follows:

      initial_list=[content]
      second_list=[]
      for member in range(0,len(initial_list)):
         sample(i, 100)
         randommember=random.int(0,99)[member]
         second_list.append(pop_array[randommember])

However the command keeps returning "'module' object has no attribute 'int'", because I can't seem to utilise member such that the random.int function can iterate through it. Any tips?




Aucun commentaire:

Enregistrer un commentaire