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


Groups > comp.lang.python > #79338

Re: Building lists

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!news.astraweb.com!border5.newsrouter.astraweb.com!not-for-mail
From Seymore4Head <Seymore4Head@Hotmail.invalid>
Newsgroups comp.lang.python
Subject Re: Building lists
Date Mon, 20 Oct 2014 16:55:09 -0400
Message-ID <03ta4ahogsj145ijd7lfshm7emh6hh52gh@4ax.com> (permalink)
References <obja4a5ij57rtuaivtvcuqsufhuhk3a2su@4ax.com> <mailman.15001.1413834029.18130.python-list@python.org> <6jpa4ahhc8ln7hk8s0258hvqd3io51epa0@4ax.com> <mailman.15005.1413835170.18130.python-list@python.org> <g9ra4adb83v03vjarh5vlhgpff0mhkilt7@4ax.com> <mailman.15007.1413837963.18130.python-list@python.org>
X-Newsreader Forte Agent 4.2/32.1118
MIME-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Transfer-Encoding 7bit
Lines 47
Organization Unlimited download news at news.astraweb.com
NNTP-Posting-Host c3022de7.news.astraweb.com
X-Trace DXC=ea9IWkioh8B?9YCQO^`6:EL?0kYOcDh@JQE8=9WgQZkKi?6[h085cfMl9B_G1R=S=G<>a^elBcbLIL\a2J2U=lbN>;G_[[=?VTFoSn>ZUiZC9EiZkK5V;eOoE
Xref csiph.com comp.lang.python:79338

Show key headers only | View raw


On Mon, 20 Oct 2014 14:45:19 -0600, Ian Kelly <ian.g.kelly@gmail.com>
wrote:

>On Mon, Oct 20, 2014 at 2:23 PM, Seymore4Head
><Seymore4Head@hotmail.invalid> wrote:
>> On Mon, 20 Oct 2014 13:58:46 -0600, Ian Kelly <ian.g.kelly@gmail.com>
>> wrote:
>>
>>>On Mon, Oct 20, 2014 at 1:49 PM, Seymore4Head
>>><Seymore4Head@hotmail.invalid> wrote:
>>>> For starters I would like to know if you can make a single item list
>>>> and then turn it into a 2 item list.  Is there a command for that?
>>>
>>>You mean like this?
>>>
>>>>>> the_list = ['first_item']
>>>>>> the_list.append('second_item')
>>>>>> the_list
>>>['first_item', 'second_item']
>>
>>
>> a=(1,2,3)
>> b=("Red", "Green", "Blue")
>> c=("a"."b,"c")
>>
>> d=(1,red,a 2,green,b 3,blue,c)
>>
>> Something like that.
>
>Those are tuples, not lists. Are you trying to create a list of tuples
>from a, b, and c? If so, then zip does what you want:
>
>>>> d = list(zip(a, b, c))
>>>> d
>[(1, 'Red', 'a'), (2, 'Green', 'b'), (3, 'Blue', 'c')]
>
>Or do you want all those elements merged into a single list?
>
>>>> d = list(sum(zip(a, b, c), ()))
>>>> d
>
>[1, 'Red', 'a', 2, 'Green', 'b', 3, 'Blue', 'c']

I am not sure really.  I know I need more practice, but I haven't
found a reliable way to find practice problems.

Thank you

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


Thread

Building lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-20 14:10 -0400
  Re: Building lists sohcahtoa82@gmail.com - 2014-10-20 11:18 -0700
    Re: Building lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-20 14:21 -0400
      Re: Building lists sohcahtoa82@gmail.com - 2014-10-20 11:33 -0700
        Re: Building lists Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-20 20:55 +0100
  Re: Building lists MRAB <python@mrabarnett.plus.com> - 2014-10-20 20:40 +0100
    Re: Building lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-20 15:49 -0400
      Re: Building lists Ian Kelly <ian.g.kelly@gmail.com> - 2014-10-20 13:58 -0600
        Re: Building lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-20 16:23 -0400
          Re: Building lists Ian Kelly <ian.g.kelly@gmail.com> - 2014-10-20 14:45 -0600
            Re: Building lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-20 16:55 -0400
          Re: Building lists Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-20 21:47 +0100
      Re: Building lists Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-20 20:57 +0100
        Re: Building lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-20 16:24 -0400
      Re: Building lists Denis McMahon <denismfmcmahon@gmail.com> - 2014-10-20 22:40 +0000
        Re: Building lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-20 18:44 -0400
      Re: Building lists Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-21 10:55 +1100
        Re: Building lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-20 20:05 -0400
      Re: Building lists Larry Hudson <orgnut@yahoo.com> - 2014-10-21 00:11 -0700
        Re: Building lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-21 08:54 -0400
      Re: Building lists Larry Hudson <orgnut@yahoo.com> - 2014-10-21 00:40 -0700
        Re: Building lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-21 08:55 -0400
    Re: Building lists Denis McMahon <denismfmcmahon@gmail.com> - 2014-10-20 22:30 +0000
      Re: Building lists MRAB <python@mrabarnett.plus.com> - 2014-10-20 23:57 +0100
  Re: Building lists John Gordon <gordon@panix.com> - 2014-10-20 20:48 +0000
    Re: Building lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-20 17:25 -0400
      Re: Building lists Ian Kelly <ian.g.kelly@gmail.com> - 2014-10-20 15:34 -0600
      Re: Building lists Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-10-20 21:31 -0400
        Re: Building lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-21 08:55 -0400
  Re: Building lists Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-10-21 10:54 +1300
    Re: Building lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-20 17:57 -0400
  Re: Building lists Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-10-20 21:27 -0400

csiph-web