Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with lists
#3
Hi

OK - yes,you're right. The thing is that I simply can't figure out how. Now, based on you're reply, I tried to put in the following, which seem more clear. Still doesn't work - or in fact I'm not sure because I don't get any response in my VScode, which could lead to something being absolutely wrong in the code.

import random
nouns = ["fossil", "horse", "aardvark", "judge", "chef", "mango", "gorilla"]

new_lst =  []
i = 0

while i < 3 :
    select_noun = random.choice(nouns)
    if select_noun.index in new_lst == False :
        new_lst.append(select_noun)

i = len(new_lst)

print (new_lst)
Can you find the problem in this?

Cheers
Reply


Messages In This Thread
Help with lists - by Blaedel - Feb-25-2019, 09:13 PM
RE: Help with lists - by Yoriz - Feb-25-2019, 11:26 PM
RE: Help with lists - by Blaedel - Feb-26-2019, 06:55 AM
RE: Help with lists - by buran - Feb-26-2019, 07:32 AM
RE: Help with lists - by perfringo - Feb-26-2019, 08:23 AM
RE: Help with lists - by Blaedel - Feb-26-2019, 05:46 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020