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
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)._
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
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
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
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
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
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
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
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)])):
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
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]))
...
>>>
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)
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
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
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.
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
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
18 matches
Mail list logo