Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #43356

Fwd: use a loop to create lists

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <kelnreiter@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.009
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'syntax': 0.04; '(python': 0.07; 'tom': 0.07; 'posting.': 0.09; 'received:209.85.219': 0.09; 'subject:create': 0.09; 'creates': 0.14; '&gt;&gt;': 0.16; '2.6.4': 0.16; 'dict': 0.16; 'goebel': 0.16; 'machine?': 0.16; 'typo': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'thu,': 0.19; 'written': 0.21; 'email addr:gmail.com&gt;': 0.22; 'replace': 0.24; '&gt;': 0.26; '----------': 0.26; 'header:In-Reply-To:1': 0.27; 'direction': 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; "skip:' 10": 0.31; '2009,': 0.31; 'keys': 0.31; 'lists': 0.32; 'running': 0.33; 'date:': 0.34; 'maybe': 0.34; 'received:209.85': 0.35; 'subject:lists': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'i.e.': 0.36; 'thanks': 0.36; 'should': 0.36; 'detail': 0.37; 'wrong': 0.37; 'too': 0.37; 'list': 0.37; 'list.': 0.37; 'received:209': 0.37; 'thank': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'forwarded': 0.39; 'subject:': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'subject:Fwd': 0.61; 're:': 0.63; 'thomas': 0.65; 'between': 0.67; 'as:': 0.81; 'tom,': 0.84; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=5SaKrujJHwKk6mXf3bj9dirLdG1aSO5zn9e0jkHdSA4=; b=z54suE3E6FjdyWto68u2sgh6enijuZjfEdEES8fnZLqM+gHumysgW2y9wXzWzeiCZ9 Zznh9PAqNi/izNjmNx9fmxK6F5YwAMt01dOogq3F6agiaaZFkEnaX2TMmsNNjQ4hFULa kKVuJlT2ir/sy/xJ99RMSvzYuHpNAG6HRdartVz9eREukQlbbAjVB0J9APyesv0fboFX IO8l/Oo0BhywbqJsOU6QyXLOnOYtHV3UkbbJp0yJ7lwyNroSP84auJwl+jIJzA85eruq BqEhlSMEQJF7RMyUtQYovy9Z1KkcDy8NKe1NAwvKmaeR6CpHNmMl/dTPoP9/2vlT9IUy DqlQ==
MIME-Version 1.0
X-Received by 10.182.33.102 with SMTP id q6mr2187718obi.39.1365682312780; Thu, 11 Apr 2013 05:11:52 -0700 (PDT)
In-Reply-To <CAOjpqbM80RTXQsxgLJ9R_5X8uezWZQKcZ3F_fN8_vuq1D7_JoA@mail.gmail.com>
References <4c47da9e-c632-4855-98a7-0506d8013046@googlegroups.com> <51656F6A.5040103@th-nuernberg.de> <CAOjpqbPmjO1YS2N+931Q6+0NkHALnFocBydBtnhRxjHDf_d-DQ@mail.gmail.com> <5166A297.70104@th-nuernberg.de> <CAOjpqbM80RTXQsxgLJ9R_5X8uezWZQKcZ3F_fN8_vuq1D7_JoA@mail.gmail.com>
Date Thu, 11 Apr 2013 14:11:52 +0200
Subject Fwd: use a loop to create lists
From Franz Kelnreiter <kelnreiter@gmail.com>
To python-list@python.org
Content-Type multipart/alternative; boundary=047d7b5d90b521240904da14b1e3
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.464.1365682322.3114.python-list@python.org> (permalink)
Lines 129
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1365682322 news.xs4all.nl 2666 [2001:888:2000:d::a6]:58816
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:43356

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

---------- Forwarded message ----------
From: Franz Kelnreiter <kelnreiter@gmail.com>
Date: Thu, Apr 11, 2013 at 2:09 PM
Subject: Re: use a loop to create lists
To: Thomas.Goebel@ohm-hochschule.de


On Thu, Apr 11, 2013 at 1:46 PM, Thomas Goebel <
Thomas.Goebel@ohm-hochschule.de> wrote:

> * On 11/04/2013 13:25, Franz Kelnreiter wrote:
> > On Wed, Apr 10, 2013 at 3:55 PM, Thomas Goebel wrote:
> >>
> >> global_list = {'_'.join(['list', str(i)]):[] for i in range(20)}
> >> global_list_1 = global_list['list_0'] --
> >
> > Sorry Thomas, but you had a typo or in any case a wrong syntax
> > concept in your last posting. If you'd like to use list
> > comprehension it should be written as:
> >
> > mydict = {'_'.join(['list', str(i)]):[x for x in range(20)]}
>
> Hi Franz,
>
> the difference between your and my code is that
>
> global_list = {'_'.join(['list', str(i)]):[] for i in range(20)}
>
> creates a dict 'global_list' which has 20 keys named from 'list_0' to
> 'list_19'. The value for all keys is an empty list. If you want to
> create i.e. 20 keys which value is a list with 20 ints you have to use
>
> global_list = ({'_'.join(['list', str(i)]):[a for a in range(20)] for
>     i in range(20)})
>
> Your code creates a dict with one key 'list_19' which value is a list
> with 20 ints if you replace str(i) with str(a).
>
> Regards, Tom
>

Tom,
Thanks for your explanation, I think I know what you want to do and I would
very much like to understand your code in detail - maybe I am too stupid -
but when I execute the value part of your code construct:

[a for a in range(20)] for i in range(20)

I get a syntax error, as I exepected (Python 2.6.4 (r264:75708, Oct 26
2009, 08:23:19)).

So how can you get me on the right direction to make your code running on
my machine?

Thank you, Franz

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

use a loop to create lists martaamunar@gmail.com - 2013-04-10 01:40 -0700
  Re: use a loop to create lists Chris Angelico <rosuav@gmail.com> - 2013-04-10 18:52 +1000
  Re: use a loop to create lists Dave Angel <davea@davea.name> - 2013-04-10 08:36 -0400
  Re: use a loop to create lists rusi <rustompmody@gmail.com> - 2013-04-10 08:31 -0700
  Re: use a loop to create lists Thomas Goebel <Thomas.Goebel@ohm-hochschule.de> - 2013-04-10 15:55 +0200
  Fwd: use a loop to create lists Franz Kelnreiter <kelnreiter@gmail.com> - 2013-04-11 14:11 +0200
  Re: use a loop to create lists Thomas Goebel <Thomas.Goebel@ohm-hochschule.de> - 2013-04-11 14:57 +0200
  Re: use a loop to create lists Chris Angelico <rosuav@gmail.com> - 2013-04-11 23:22 +1000
  Re: Fwd: use a loop to create lists Thomas Goebel <Thomas.Goebel@ohm-hochschule.de> - 2013-04-11 15:43 +0200
  Re: use a loop to create lists Franz Kelnreiter <kelnreiter@gmail.com> - 2013-04-11 16:11 +0200
  Re: use a loop to create lists Thomas Goebel <Thomas.Goebel@ohm-hochschule.de> - 2013-04-11 16:33 +0200
  Re: Fwd: use a loop to create lists Franz Kelnreiter <kelnreiter@gmail.com> - 2013-04-11 16:33 +0200
  Re: use a loop to create lists Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-04-11 18:17 -0400

csiph-web