Re: py itertools?

2009-12-20 Thread Parker
a = 'qwerty' b = '^%$#' c = [(x,y) for x in a for y in b] c [('q', '^'), ('q', '%'), ('q', ''), ('q', '$'), ('q', '#'), ('w', '^'), ('w', '%'), ('w', ''), ('w', '$'), ('w', '#'), ('e', '^'), ('e', '%'), ('e', ''), ('e', '$'), ('e', '#'), ('r', '^'), ('r', '%'), ('r', ''), ('r', '$'), ('r',

Re: py itertools?

2009-12-20 Thread Chris Rebert
On Dec 19, 12:48 pm, Chris Rebert c...@rebertia.com wrote: On Sat, Dec 19, 2009 at 2:54 AM, mattia ger...@gmail.com wrote: Hi all, I need to create the permutation of two strings but without repeat the values, e.g. 'ab' for me is equal to 'ba'. Here is my solution, but maybe the python

Re: py itertools?

2009-12-20 Thread mattia
Il Sun, 20 Dec 2009 03:49:35 -0800, Chris Rebert ha scritto: On Dec 19, 12:48 pm, Chris Rebert c...@rebertia.com wrote: On Sat, Dec 19, 2009 at 2:54 AM, mattia ger...@gmail.com wrote: Hi all, I need to create the permutation of two strings but without repeat the values, e.g. 'ab' for me is

py itertools?

2009-12-19 Thread mattia
Hi all, I need to create the permutation of two strings but without repeat the values, e.g. 'ab' for me is equal to 'ba'. Here is my solution, but maybe the python library provides something better: def mcd(a, b): ... if b == 0: ... return a ... else: ... return mcd(b,

Re: py itertools?

2009-12-19 Thread Chris Rebert
On Sat, Dec 19, 2009 at 2:54 AM, mattia ger...@gmail.com wrote: Hi all, I need to create the permutation of two strings but without repeat the values, e.g. 'ab' for me is equal to 'ba'. Here is my solution, but maybe the python library provides something better: def mcd(a, b): ...     if b

Re: py itertools?

2009-12-19 Thread Lie Ryan
On 12/19/2009 11:48 PM, Chris Rebert wrote: Surprised you didn't think of the seemingly obvious approach: def permute_chars(one, two): for left in set(one): for right in set(two): yield (left, right) list(permute_chars('abc', 'wt')) [('a', 'w'), ('a', 't'), ('b',

Re: py itertools?

2009-12-19 Thread mattia
Il Sat, 19 Dec 2009 10:54:58 +, mattia ha scritto: Hi all, I need to create the permutation of two strings but without repeat the values, e.g. 'ab' for me is equal to 'ba'. Here is my solution, but maybe the python library provides something better: def mcd(a, b): ... if b == 0: