[Tutor] How can I replicate a list in a for loop

Alan Gauld alan.gauld at btinternet.com
Wed Feb 4 09:03:52 CET 2015


On 03/02/15 22:51, Suresh Nagulavancha wrote:
> This is my sample piece of code (not full code of my original code just sample of it)
> I am using python 2.7
> Import itertools
> var=[1,2,3,4,5]
> Length=int(raw_input("length of possible numbers required"))
> #This is for length of 3 chars
> for i in itertools.product(var,var,var):
>        print i[0]+i[1]+i[2]
>
>
> Here what is my problem is i am unable to replicate the list based
 >  on the user input i tried var*length but it is creating a new
 > single list with repeated values , how can i solve this problem??
 > I want the same original list to be used

Sorry, I couldn't follow that. Can you provide some sample data,
some inputs and some outputs to show what you expected and what
you got?

tia
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list