Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #99908
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: HELP PLEASE printing single characters! |
| Date | Wed, 2 Dec 2015 13:08:21 -0600 |
| Lines | 34 |
| Message-ID | <mailman.143.1449083343.14615.python-list@python.org> (permalink) |
| References | <75854ef5-fdd5-49da-88e8-27687b8d31c6@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | quoted-printable |
| X-Trace | news.uni-berlin.de E3tQHjNmxroGd+xatYgRiQe+gQ7A7kmASetRxFBmKngg== |
| Return-Path | <ian.g.kelly@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.010 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'received:209.85.223': 0.03; 'any.': 0.09; 'subject:characters': 0.09; 'wed,': 0.15; '#create': 0.16; 'is",': 0.16; 'iterable,': 0.16; 'iterating': 0.16; 'list)': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'element': 0.18; 'all,': 0.20; '2015': 0.20; 'trying': 0.22; 'dec': 0.23; 'elements': 0.23; 'import': 0.24; 'words': 0.24; 'header:In-Reply-To:1': 0.24; 'example': 0.26; 'figure': 0.27; 'order.': 0.27; 'message-id:@mail.gmail.com': 0.27; 'prints': 0.29; 'random': 0.29; 'print': 0.30; 'code': 0.30; 'list': 0.34; 'received:google.com': 0.35; 'should': 0.36; 'received:209.85': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:209': 0.38; 'skip:p 20': 0.38; 'why': 0.39; 'does': 0.39; 'takes': 0.39; 'to:addr:python.org': 0.40; 'results': 0.66; 'repeat': 0.67; 'day': 0.67; 'riley': 0.84; 'subject:printing': 0.84; 'to:name:python': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; bh=URnTyGOBYsA5ci2YIOLNdLqSYqFLBp+uLRHkiW18hq0=; b=zDp61LKgfGhsSyEUg7kQAhqAMrzIbYyjFJoggUtHq92N5TQ3B3zlqnBbT1UKKTA5ti tTa9x33+d6Wv6ReHlGqV8Rn3oBxU/3BTFm3lEO+h53OcsIof4q8j6uuuEVeaQhGapq5/ XlnPwy1RBVOyZWYFtP7Q68WJF8X8pwF7EvA7MojFq8q9Iyu7MqeGtQppv+t1V6mNudWQ oLJP4Lu9DW3tES34TuYmfUR0z6tTfqRuFA1FrwKEIc6cbnJUAOAU/t72GLzZmI8gMn9P 1xTDyaQHddw3x5nQlay/vVlqTcWN41ym+AQq80xIDrq/mY7y721lfUzrr6RZdpXHCdR5 ZKmw== |
| X-Received | by 10.107.19.12 with SMTP id b12mr5904566ioj.11.1449083340859; Wed, 02 Dec 2015 11:09:00 -0800 (PST) |
| In-Reply-To | <75854ef5-fdd5-49da-88e8-27687b8d31c6@googlegroups.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:99908 |
Show key headers only | View raw
On Wed, Dec 2, 2015 at 12:58 PM, Dylan Riley <dylan.riley@hotmail.com> wrote:
> hi all,
> I have been trying to figure out all day why my code is printing single characters 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, print(LIST[random.choice]) i get:
> ["e", "x", "a", "m", "p", "l", "e"] when i should get ["example"].
Remember that strings are iterable, and that iterating over strings
results in individual characters. That should give you a clue as to
what's going on.
> 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.
>
> import random
>
> LIST = ["blue ", "red ", "yellow ", "green ", "orange "]
> order = []
>
> print("This game will print a random order of colours")
> print("The list is", LIST)
> input("press enter to start")
>
>
>
> while LIST != []:
> choice = random.choice(LIST)
> order += choice
Addition on a list does concatenation, not appending. So this takes
each element from choice and adds them individually to order.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
HELP PLEASE printing single characters! Dylan Riley <dylan.riley@hotmail.com> - 2015-12-02 10:58 -0800
Re: HELP PLEASE printing single characters! Ian Kelly <ian.g.kelly@gmail.com> - 2015-12-02 13:08 -0600
Re: HELP PLEASE printing single characters! Dylan Riley <dylan.riley@hotmail.com> - 2015-12-02 11:44 -0800
Re: HELP PLEASE printing single characters! Ian Kelly <ian.g.kelly@gmail.com> - 2015-12-02 14:15 -0600
Re: HELP PLEASE printing single characters! John Strick <jstrickler@gmail.com> - 2015-12-02 16:08 -0800
Re: HELP PLEASE printing single characters! Larry Hudson <orgnut@yahoo.com> - 2015-12-03 20:08 -0800
csiph-web