Re: Array of Chars to String

2005-04-21 Thread "Martin v. Löwis"
Bengt Richter wrote: > But since I'm playing the other side of the table for > the moment, isn't filter to be deprecated? How could we know? It might be removed in P3k, but does that mean it is deprecated, as in "being disapproved", i.e. "being passed unfavorable judgement on"? In Python, I consi

Re: Array of Chars to String

2005-04-21 Thread Bengt Richter
On Thu, 21 Apr 2005 07:34:09 +0200, =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?= <[EMAIL PROTECTED]> wrote: >James Stroud wrote: >> astr = "Bob Carol Ted Alice" >> letters = "adB" > >Apparently nobody has proposed this yet: > filter(letters.__contains__, astr) >'Bad' filter(set(letters)._

Re: Array of Chars to String

2005-04-21 Thread Michael Spencer
Martin v. Löwis wrote: Apparently nobody has proposed this yet: >>>filter(letters.__contains__, astr) 'Bad' >>>filter(set(letters).__contains__, astr) 'Bad' Everyone is seeking early PEP 3000 compliance ;-) filter wins on conciseness - it's short enought to use in-line, but for a fair speed compa

Re: Array of Chars to String

2005-04-20 Thread "Martin v. Löwis"
James Stroud wrote: > astr = "Bob Carol Ted Alice" > letters = "adB" Apparently nobody has proposed this yet: >>> filter(letters.__contains__, astr) 'Bad' >>> filter(set(letters).__contains__, astr) 'Bad' Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list

Re: Array of Chars to String

2005-04-20 Thread Michael Spencer
Kent Johnson wrote: Michael Spencer wrote: Anyway, here are the revised timings... ... print shell.timefunc(func_translate1, "Bob Carol Ted Alice" * multiplier, 'adB') What is shell.timefunc? This snippet, which I attach to my interactive shell, since I find timeit awkward to use in that co

Re: Array of Chars to String

2005-04-20 Thread Kent Johnson
Michael Spencer wrote: Anyway, here are the revised timings... ... print shell.timefunc(func_translate1, "Bob Carol Ted Alice" * multiplier, 'adB') What is shell.timefunc? Thanks, Kent -- http://mail.python.org/mailman/listinfo/python-list

Re: Array of Chars to String

2005-04-20 Thread Michael Spencer
Peter Otten wrote: Michael Spencer wrote: def func_join(s, letters): ... return "".join(letter for letter in s if letter in set(letters)) Make that def func_join(s, letters): letter_set = set(letters) return "".join(letter for letter in s if letter in letter_set) for a fair timing o

Re: Array of Chars to String

2005-04-20 Thread Scott David Daniels
Bengt Richter wrote: ... BTW, since str has .translate, why not .maketrans? Probably because, while I can imagine u'whatever'.translate using a 256-wide table (and raising exceptions for other the rest), I have more problems imagining the size of the table for a UCS-4 unicode setup (32 bits per cha

Re: Array of Chars to String

2005-04-20 Thread Peter Otten
Michael Spencer wrote: > >>> def func_join(s, letters): > ... return "".join(letter for letter in s if letter in set(letters)) Make that def func_join(s, letters): letter_set = set(letters) return "".join(letter for letter in s if letter in letter_set) for a fair timing of a set lo

Re: Array of Chars to String

2005-04-19 Thread Bengt Richter
On Tue, 19 Apr 2005 17:00:02 -0700, Michael Spencer <[EMAIL PROTECTED]> wrote: >Michael Spencer wrote: >> Bengt Richter wrote: >> > I think this will be worth it if your string to modify is _very_ long: >> >>> >>> >>> def some_func(s, letters, table=''.join([chr(i) for i in >>> xrange(256)])):

Re: Array of Chars to String

2005-04-19 Thread Michael Spencer
Michael Spencer wrote: Bengt Richter wrote: > I think this will be worth it if your string to modify is _very_ long: >>> def some_func(s, letters, table=''.join([chr(i) for i in xrange(256)])): ... return s.translate(table, ...''.join([chr(i) for i in xrange(256) if chr(i) not

Re: Array of Chars to String

2005-04-19 Thread Michael Spencer
Bengt Richter wrote: > I think this will be worth it if your string to modify is _very_ long: >>> def some_func(s, letters, table=''.join([chr(i) for i in xrange(256)])): ... return s.translate(table, ...''.join([chr(i) for i in xrange(256) if chr(i) not in letters])) ... >>>

Re: Array of Chars to String

2005-04-19 Thread Bengt Richter
On Tue, 19 Apr 2005 13:33:17 -0700, James Stroud <[EMAIL PROTECTED]> wrote: >Hello, > >I am looking for a nice way to take only those charachters from a string that >are in another string and make a new string: > astr = "Bob Carol Ted Alice" letters = "adB" some_func(astr,letters)

Re: Array of Chars to String

2005-04-19 Thread rbt
James Stroud wrote: Hello, I am looking for a nice way to take only those charachters from a string that are in another string and make a new string: astr = "Bob Carol Ted Alice" letters = "adB" some_func(astr,letters) "Bad" astr = "Bob Carol Ted Alice" letters = "adB" both = [x for x in astr if

Re: Array of Chars to String

2005-04-19 Thread Facundo Batista
On 4/19/05, James Stroud <[EMAIL PROTECTED]> wrote: > astr = "Bob Carol Ted Alice" > letters = "adB" > > import sets > alist = [lttr for lttr in astr if lttr in Set(letters)] > newstr = "" > for lttr in alist: > newstr += lttr >>> astr = "Bob Carol Ted Alice" >>> letters = "adB" >>> s1 = set(a

Re: Array of Chars to String

2005-04-19 Thread Alexander Schmolck
James Stroud <[EMAIL PROTECTED]> writes: > But this seems ugly. I especially don't like "newstr += lttr" because it > makes > a new string every time. I am thinking that something like this has to be a > function somewhere already or that I can make it more efficient using a > built-in tool.

Re: Array of Chars to String

2005-04-19 Thread Michael Spencer
James Stroud wrote: Hello, I am looking for a nice way to take only those charachters from a string that are in another string and make a new string: astr = "Bob Carol Ted Alice" letters = "adB" some_func(astr,letters) "Bad" I can write this like this: astr = "Bob Carol Ted Alice" letters = "adB

Array of Chars to String

2005-04-19 Thread James Stroud
Hello, I am looking for a nice way to take only those charachters from a string that are in another string and make a new string: >>> astr = "Bob Carol Ted Alice" >>> letters = "adB" >>> some_func(astr,letters) "Bad" I can write this like this: astr = "Bob Carol Ted Alice" letters = "adB" imp