---------- Forwarded message ---------- From: Zero Piraeus <sche...@gmail.com> Date: Tue, Oct 23, 2012 at 11:14 AM Subject: Re: can we append a list with another list in Python ? To: inshu chauhan <insidesh...@gmail.com>
: On 23 October 2012 05:01, inshu chauhan <insidesh...@gmail.com> wrote: > this is because this makes a single list out of 2 lists.. but I want to retain both lists as lists within list....... I hope u got it ?? > > my problem is for example : > > x = [1,2,3] > y = [10, 20, 30] > > I want the output to be : > > [[1,2,3], [10, 20, 30]] .. a list within list > > then i want to process each list in the big list using another function ???? For the example above, you'd just do: >>> x = [1, 2, 3] >>> y = [10, 20, 30] >>> z = [x, y] >>> z [[1, 2, 3], [10, 20, 30]] ... but presumably there'll be more than two, and you're creating them in some kind of loop? In that case, append is fine. For example: >>> result = [] >>> for word in "squee", "kapow", "vroom": ... seq = list(word) # or whatever you're doing to create the list ... result.append(seq) ... >>> result [['s', 'q', 'u', 'e', 'e'], ['k', 'a', 'p', 'o', 'w'], ['v', 'r', 'o', 'o', 'm']] By the way - you only replied to me. Do you mind if I forward this back to the list? -[]z.
-- http://mail.python.org/mailman/listinfo/python-list