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

2015-02-04 Thread Alan Gauld
On 04/02/15 13:06, Raúl Cumplido wrote: There is a repeat argument on the product function that is used exactly for what you want to do: >>> for s in product(var, repeat=2) print ''.join(s) Good catch, I should have remembered that. -- Alan G Author of the Learn to Program web site

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

2015-02-04 Thread Raúl Cumplido
There is a repeat argument on the product function that is used exactly for what you want to do: >>> for s in product(var, repeat=2) print ''.join(s) On Wed, Feb 4, 2015 at 1:01 PM, Raúl Cumplido wrote: > sorry, just me being stupid :P should have read closely what the problem > was

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

2015-02-04 Thread Raúl Cumplido
sorry, just me being stupid :P should have read closely what the problem was On Wed, Feb 4, 2015 at 12:54 PM, Raúl Cumplido wrote: > I think you want to use combinations_with_replacement: > > >>> var = ['a', 'b', 'c', 'd', 'e'] > > >>> length=int(raw_input("enter the length of random letters you

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

2015-02-04 Thread Raúl Cumplido
I think you want to use combinations_with_replacement: >>> var = ['a', 'b', 'c', 'd', 'e'] >>> length=int(raw_input("enter the length of random letters you need ")) enter the length of random letters you need 2 >>> length 2 >>> from itertools import combinations_with_replacement >>> [''.join(s

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

2015-02-04 Thread Alan Gauld
On 04/02/15 09:46, Suresh Kumar wrote: print var ['a', 'b', 'c', 'd', 'e'] the user gave two so code should be like this for i in itertools.product(var,var): print i[0]+i[1] output of code should be like this aa ab ... ee based on the user given input of length i need t

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

2015-02-04 Thread Suresh Kumar
here is the sample code >>> import itertools >>> import string >>> var=[] >>> for i in string.ascii_lowercase[0:5]: var.append(i) >>>print var ['a', 'b', 'c', 'd', 'e'] >>> length=int(raw_input("enter the length of random letters you need ")) enter the length of random letters you need

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

2015-02-04 Thread Alan Gauld
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 itertool

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

2015-02-03 Thread Mark Lawrence
On 03/02/2015 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 iterto

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

2015-02-03 Thread Suresh Nagulavancha
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[