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: 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; '>>': 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>': 0.22; 'replace': 0.24; '>': 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: References: <4c47da9e-c632-4855-98a7-0506d8013046@googlegroups.com> <51656F6A.5040103@th-nuernberg.de> <5166A297.70104@th-nuernberg.de> Date: Thu, 11 Apr 2013 14:11:52 +0200 Subject: Fwd: use a loop to create lists From: Franz Kelnreiter 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 --047d7b5d90b521240904da14b1e3 Content-Type: text/plain; charset=ISO-8859-1 ---------- Forwarded message ---------- From: Franz Kelnreiter 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 --047d7b5d90b521240904da14b1e3 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable


---------- Forwarded me= ssage ----------
From: Franz Kelnreiter <kelnreiter@= gmail.com>
Date: Thu, Apr 11, 2013 at 2:09 PM
Subject: Re: use a loop to create lis= ts
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 =3D {'_'.join(['list', str(i)]):[] for= i in range(20)}
>> global_list_1 =3D global_list['list_0'] --
>
> Sorry Thomas, but you had a typo or in any case a wrong syn= tax
> concept in your last posting. If you'd like to use list
> comprehension it should be written as:
>
> mydict =3D {'_'.join(['list', str(i)]):[x for x in ran= ge(20)]}

Hi Franz,

the difference between your and my code is that

global_list =3D {'_'.join(['list', str(i)]):[] for i in ran= ge(20)}

creates a dict 'global_list' which has 20 keys named from = 9;list_0' to
'list_19'. The value for all keys is an empty list. If you want to<= br> create i.e. 20 keys which value is a list with 20 ints you have to use

global_list =3D ({'_'.join(['list', str(i)]):[a for a in ra= nge(20)] for
=A0 =A0 i in range(20)})

Your code creates a dict with one key 'list_19' which value is a li= st
with 20 ints if you replace str(i) with str(a).

Regards, Tom

Tom,=A0
<= div>Thanks for your explanation, I think I know what you want to do and I w= ould very much like to understand your code in detail - maybe I am too stup= id - 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 (r= 264:75708, Oct 26 2009, 08:23:19)).

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

Thank you, Franz
=

--047d7b5d90b521240904da14b1e3--