can we append a list with another list in Python ?

inshu chauhan insideshoes at gmail.com
Thu Oct 25 05:58:41 EDT 2012


Yes Dave ..You are right and my problem is solved now..  Thanx to all...

On Thu, Oct 25, 2012 at 11:55 AM, David Hutto <dwightdhutto at gmail.com>wrote:

> On Thu, Oct 25, 2012 at 5:51 AM, inshu chauhan <insideshoes at gmail.com>
> wrote:
> >
> >
> >>
> >> Is this what you mean:
> >>
> list_0 = []
> list_1 = [i for i in range(0,5)]
> list_2 = [i for i in range(5,11)]
> list_0.append(list_1)
> list_0.append(list_2)
> >> >>> for i in list_2:
> >> ...     list_1.append(i)
> >> ...
> >> >>> list_1
> >> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
> >>
> >>
> >> or would another example help you out more?
> >
> >
> > No but really sorry this is what I DONT WANT.......
> >
> > The output I want to have is :
> >
> > [ [0, 1, 2, 3, 4 ], [5, 6, 7, 8, 9, 10] ].....
>
> Then, this is what you want :
>
> >>david at david-desktop:~$ python
> Python 2.7.3 (default, Aug  1 2012, 05:16:07)
> [GCC 4.6.3] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> list_0 = []
> >>> list_1 = [i for i in range(0,5)]
> >>> list_2 = [i for i in range(5,11)]
> >>> list_0.append(list_1)
> >>> list_0.append(list_2)
> >>> list_0
> [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9, 10]]
> >>>
>
>
>
>
> --
> Best Regards,
> David Hutto
> CEO: http://www.hitwebdevelopment.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20121025/c7ccf036/attachment.html>


More information about the Python-list mailing list