cian
cian

Reputation: 59

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)):
         randommember=random.randint(0,99)
         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. I am aware that I could do this using strings and random.choice() but I have ulterior reasons for using lists and random.int(). Any tips?

Upvotes: 2

Views: 84

Answers (1)

TigerhawkT3
TigerhawkT3

Reputation: 49318

First, it's random.randint, not random.int. Second, you can't index an integer with another integer like you're doing with [member]. Third, you can simply use second_list.append(random.choice(pop_array)).

Upvotes: 2

Related Questions