Re: How to generate k+1 length strings from a list of k length strings?

2006-06-09 Thread Boris Borcic
> Hum, since your code is not syntactically correct, anything will run > faster :) in fact it parses, I was fooled by this line >> if k in range(1,len(prunedK),1) & i+k <= len(prunedK) -1: I was fooled because the form "k in range(" tends to imply a for statement ; in the case of an

Re: How to generate k+1 length strings from a list of k length strings?

2006-06-09 Thread Boris Borcic
[EMAIL PROTECTED] wrote: > It's not that difficult to improve the readability of a quite long > line, you can start splitting it. The point is that it is observer and context dependent whether res = set(''.join(sorted(X|Y)) for X in sets for Y in sets

Re: How to generate k+1 length strings from a list of k length strings?

2006-06-09 Thread Boris Borcic
[EMAIL PROTECTED] wrote: > Boris Borcic: >>> I don't do challenges. >> Pfff... and you don't do real debates either. > > Different nations have different values and different cultures, in mine > challenges are often seen as things for children, and a waste of time > for adults (probably in USA cha

Re: How to generate k+1 length strings from a list of k length strings?

2006-06-09 Thread bearophileHUGS
Boris Borcic: > > I don't do challenges. > > Pfff... and you don't do real debates either. Different nations have different values and different cultures, in mine challenges are often seen as things for children, and a waste of time for adults (probably in USA challenges are appreciated more). By

Re: How to generate k+1 length strings from a list of k length strings?

2006-06-09 Thread Boris Borcic
[EMAIL PROTECTED] wrote: > Boris Borcic: > >> I challenge you to write simpler code to do the equivalent. context ? > > I don't do challenges. Pfff... and you don't do real debates either. > I too have written the code to solve that > problem, Why ? When ? -- http://mail.python.org/mailman/

Re: How to generate k+1 length strings from a list of k length strings?

2006-06-08 Thread bearophileHUGS
Boris Borcic: > I challenge you to write simpler code to do the equivalent. I don't do challenges. I too have written the code to solve that problem, it wasn't much different from your one (it uses a generator function xpairs, to yeild a scan of the different pairs, about half the square, it uses

Re: How to generate k+1 length strings from a list of k length strings?

2006-06-08 Thread Boris Borcic
[EMAIL PROTECTED] wrote: > Boris Borcic: >> I'd favor the following, that I find most readable >> sets = map(set,list_of_strings) >> res = set(''.join(sorted(s1|s2)) for s1 in sets for s2 in sets if >> len(s1^s2)==2) > > I think there can be written more readable code. readability, of course, is

Re: How to generate k+1 length strings from a list of k length strings?

2006-06-08 Thread bearophileHUGS
> I think there can be written more readable code. For my programs I > usually prefer simpler code, that (if possible) even a children can > understand. So I can debug, modify and improve it better & faster. Debugged: I think it can be written more readable code. In this newsgroup sometimes I have

Re: How to generate k+1 length strings from a list of k length strings?

2006-06-08 Thread bearophileHUGS
Boris Borcic: > I'd favor the following, that I find most readable > sets = map(set,list_of_strings) > res = set(''.join(sorted(s1|s2)) for s1 in sets for s2 in sets if > len(s1^s2)==2) I think there can be written more readable code. For my programs I usually prefer simpler code, that (if possib

Re: How to generate k+1 length strings from a list of k length strings?

2006-06-08 Thread MTD
Jon Clements wrote: > Are you asking the question, "Which pairs of strings have one character > different in each?", or "Which pairs of strings have a substring of > len(string) - 1 in common?". > > Jon. I imagine it's the former because the latter is trivially easy, I mean _really_ trivially eas

Re: How to generate k+1 length strings from a list of k length strings?

2006-06-08 Thread Boris Borcic
Girish Sahani wrote: > I have a list of strings all of length k. For every pair of k length > strings which have k-1 characters in common, i want to generate a k+1 > length string(the k-1 common characters + 2 not common characters). > e.g i want to join 'abcd' with bcde' to get 'abcde' but i dont

Re: How to generate k+1 length strings from a list of k length strings?

2006-06-08 Thread Jon Clements
Are you asking the question, "Which pairs of strings have one character different in each?", or "Which pairs of strings have a substring of len(string) - 1 in common?". Jon. Girish Sahani wrote: > I have a list of strings all of length k. For every pair of k length > strings which have k-1 charac

Re: How to generate k+1 length strings from a list of k length strings?

2006-06-08 Thread MTD
So yeah, just to put it all together, try this. From your two Ks, it either returns K+1 if it can or an empty string. def k2k1(string1, string2): for c in string1: string2 = string2.replace(c,"",1) if len(string2) == 1: string1 += string2 else: string1 = ""

Re: How to generate k+1 length strings from a list of k length strings?

2006-06-08 Thread MTD
actually, minor fix: MTD wrote: > Try this: > > def k2k1(string1, string2): > for c in string1: > string2 = string2.replace(c,"",1) > > if len(string2) == 1: > string1 += string2 else: string1 = "" > > return string1 > > print k2k1("abcd", "ebcd

Re: How to generate k+1 length strings from a list of k length strings?

2006-06-08 Thread MTD
Try this: def k2k1(string1, string2): for c in string1: string2 = string2.replace(c,"",1) if len(string2) == 1: string1 += string2 return string1 print k2k1("abcd", "ebcd") -- http://mail.python.org/mailman/listinfo/python-list

How to generate k+1 length strings from a list of k length strings?

2006-06-07 Thread Girish Sahani
I have a list of strings all of length k. For every pair of k length strings which have k-1 characters in common, i want to generate a k+1 length string(the k-1 common characters + 2 not common characters). e.g i want to join 'abcd' with bcde' to get 'abcde' but i dont want to join 'abcd' with 'c