Re: [Tutor] How to determine if every character in one string is inanother string?

2007-07-25 Thread Kent Johnson
Alan Gauld wrote: Terry Carroll [EMAIL PROTECTED] wrote if Y in X: FWIW I believe that 'in' did only work for single characters up until version 2.X so your ideas may have been based on experiences with an earlier Python version. Yes, it changed in Python 2.3. Kent

Re: [Tutor] How to determine if every character in one string is inanother string?

2007-07-25 Thread Alan Gauld
Terry Carroll [EMAIL PROTECTED] wrote if Y in X: Which is much more elegant/pythonic; but I didn't know you could do that with one string over another. For some reason, I had thought Y would have to exactly match one iterable element in X (e.g., one element of a list, or one

Re: [Tutor] How to determine if every character in one string is inanother string?

2007-07-25 Thread Terry Carroll
On Tue, 24 Jul 2007, wesley chun wrote: i don't have any time myself either (getting ready for OSCON talk), but i'm not sure what terry's OP was about... looking for a well-written piece of code, a faster-performing snippet, or both? i think he was just unsatissfied with his 1st attempt.

Re: [Tutor] How to determine if every character in one string is inanother string?

2007-07-24 Thread wesley chun
any() and all() also short-circuit, and they move the iteration out of Python into the C runtime. My guess is the solutions with any() and all() and equivalent hoisting of string.printable will be faster than yours, but I don't want to take the time to check ATM...I would also try using

Re: [Tutor] How to determine if every character in one string is inanother string?

2007-07-23 Thread Terry Carroll
On Sun, 22 Jul 2007, Jerry Hill wrote: On 7/21/07, Alan Gauld [EMAIL PROTECTED] wrote: all(char in string.printable for char in testString) What is all? Is that a 2.5 thing (I'm still on 2.4 here) Yes, it's a 2.5 thing. That was my favorite, too. I didn't notice the new all method

Re: [Tutor] How to determine if every character in one string is inanother string?

2007-07-23 Thread wesley chun
all(char in string.printable for char in testString) That was my favorite, too. I didn't notice the new all method in 2.5. It certainly seems the most Pythonic approach. all() has a sister built-in function, also introduced in 2.5, so i think that any(char not in string.printable for

Re: [Tutor] How to determine if every character in one string is inanother string?

2007-07-23 Thread Kent Johnson
wesley chun wrote: from string import printable as prglobal def printable(s): prlocal = prglobal for x in s: if x not in prlocal: return False return True the solutions using LCs above are great when it comes to an expressive piece of code in a

Re: [Tutor] How to determine if every character in one string is inanother string?

2007-07-22 Thread Jerry Hill
On 7/21/07, Alan Gauld [EMAIL PROTECTED] wrote: all(char in string.printable for char in testString) What is all? Is that a 2.5 thing (I'm still on 2.4 here) Yes, it's a 2.5 thing. All returns true if all of the elements of an iterable are true. According to the docs, it is the equivalent

Re: [Tutor] How to determine if every character in one string is inanother string?

2007-07-21 Thread Alan Gauld
Jerry Hill [EMAIL PROTECTED] wrote I like this one: all(char in string.printable for char in testString) What is all? Is that a 2.5 thing (I'm still on 2.4 here) testString = qwerty\buiop all(char in string.printable for char in testString) False -- Jerry