X-Received: by 10.66.190.163 with SMTP id gr3mr5540903pac.45.1449101305025; Wed, 02 Dec 2015 16:08:25 -0800 (PST) X-Received: by 10.50.155.101 with SMTP id vv5mr89498igb.8.1449101304990; Wed, 02 Dec 2015 16:08:24 -0800 (PST) Path: csiph.com!au2pb.net!feeder.erje.net!2.us.feeder.erje.net!news.ripco.com!news.glorb.com!mv3no8421045igc.0!news-out.google.com!l1ni329igd.0!nntp.google.com!mv3no8421037igc.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.python Date: Wed, 2 Dec 2015 16:08:24 -0800 (PST) In-Reply-To: <75854ef5-fdd5-49da-88e8-27687b8d31c6@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=70.43.17.173; posting-account=-eyirwoAAAAWf4yLgjsj40ZnBYqIkxfI NNTP-Posting-Host: 70.43.17.173 References: <75854ef5-fdd5-49da-88e8-27687b8d31c6@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: HELP PLEASE printing single characters! From: John Strick Injection-Date: Thu, 03 Dec 2015 00:08:24 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: csiph.com comp.lang.python:99923 On Wednesday, December 2, 2015 at 12:58:30 PM UTC-6, Dylan Riley wrote: > hi all, > I have been trying to figure out all day why my code is printing single c= haracters from my list when i print random elements using random.choice the= elements in the list are not single characters for example when i print, p= rint(LIST[random.choice]) i get: > ["e", "x", "a", "m", "p", "l", "e"] when i should get ["example"]. >=20 > my code is: > #Create a program that prints a list of words in random order. > #The program should print all the words and not repeat any. >=20 > import random >=20 > LIST =3D ["blue ", "red ", "yellow ", "green ", "orange "] > order =3D [] >=20 > print("This game will print a random order of colours") > print("The list is", LIST) > input("press enter to start") >=20 >=20 >=20 > while LIST !=3D []: > choice =3D random.choice(LIST) > order +=3D choice > while choice in LIST: > LIST.remove(choice) > print(order) > =20 > =20 > =20 > input("press enter to exit") >=20 > thanks in advance guys You could just shuffle the list first, then loop through it. This will guar= antee that each color is only used once.=20 import random LIST =3D ["blue ", "red ", "yellow ", "green ", "orange "] random.shuffle(LIST) for color in LIST: print(color) # or add to order or whatever you need to