if char in "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw xyz":
cant i write something like:
if char in "[A-Za-z]":
? 9 1837
cirfu wrote:
if char in "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw xyz":
cant i write something like:
if char in "[A-Za-z]":
Either of the following should do what you want, without resorting to
regular expressions:
import string
if char in string.letters:
or
if char.isalpha():
--
Brian
On 24 juin, 20:32, cirfu <circularf...@yahoo.sewrote:
if char in "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw xyz":
cant i write something like:
if char in "[A-Za-z]":
Nope. But there are other solutions. Here are two:
# 1
import string
if char in string.letters:
print "yay"
# 2
import re
exp = re.compile(r'[A-Za-z]')
if exp.match(char):
print "yay"
On Tue, Jun 24, 2008 at 3:47 PM, br*****************@gmail.com
<br*****************@gmail.comwrote:
On 24 juin, 20:32, cirfu <circularf...@yahoo.sewrote:
>if char in "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw xyz":
cant i write something like: if char in "[A-Za-z]":
Nope. But there are other solutions. Here are two:
# 1
import string
if char in string.letters:
print "yay"
# 2
import re
exp = re.compile(r'[A-Za-z]')
if exp.match(char):
print "yay"
Let me post another one, and longer:
if ord(somechar) in range(ord('A'), ord('Z') + 1) + range(ord('a'),
ord('z') + 1):
...
--
-- Guilherme H. Polo Goncalves
another way:
import string
if char in string.ascii_letters:
print('hello buddy!')
[]'s
- Walter
On Jun 24, 7:59*pm, "Guilherme Polo" <ggp...@gmail.comwrote:
On Tue, Jun 24, 2008 at 3:47 PM, bruno.desthuilli...@gmail.com
<bruno.desthuilli...@gmail.comwrote:
On 24 juin, 20:32, cirfu <circularf...@yahoo.sewrote:
if char in "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw xyz":
cant i write something like:
if char in "[A-Za-z]":
Nope. But there are other solutions. Here are two:
# 1
import string
if char in string.letters:
* print "yay"
# 2
import re
exp = re.compile(r'[A-Za-z]')
if exp.match(char):
* print "yay"
Let me post another one, and longer:
if ord(somechar) in range(ord('A'), ord('Z') + 1) + range(ord('a'),
ord('z') + 1):
* * ...
And another:
if 'A' <= somechar <= 'Z' or 'a' <= somechar <= 'z':
...
On Jun 25, 4:32 am, cirfu <circularf...@yahoo.sewrote:
if char in "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw xyz":
cant i write something like:
if char in "[A-Za-z]":
You can write that if you want to, but it's equivalent to
if char in "zaZa]-[":
i.e. it doesn't do what you want.
This gives the same reuslt as your original code, unaffected by
locale:
if "A" <= char <= "Z" or "a" <= char <= "z":
On Jun 24, 5:36 pm, John Machin <sjmac...@lexicon.netwrote:
On Jun 25, 4:32 am, cirfu <circularf...@yahoo.sewrote:
if char in "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw xyz":
cant i write something like:
if char in "[A-Za-z]":
You can write that if you want to, but it's equivalent to
if char in "zaZa]-[":
i.e. it doesn't do what you want.
This gives the same reuslt as your original code, unaffected by
locale:
if "A" <= char <= "Z" or "a" <= char <= "z":
But doesn't that rely on the underlying character set? It's like
performing math on C char's (maybe that's what the interpreter does
internally?). If that's the case, using 'char.isalpha()' or 'char in
string.letters' or regex's would be better.
On Jun 25, 9:06 am, s0s...@gmail.com wrote:
On Jun 24, 5:36 pm, John Machin <sjmac...@lexicon.netwrote:
On Jun 25, 4:32 am, cirfu <circularf...@yahoo.sewrote:
if char in "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw xyz":
cant i write something like:
if char in "[A-Za-z]":
You can write that if you want to, but it's equivalent to
if char in "zaZa]-[":
i.e. it doesn't do what you want.
This gives the same reuslt as your original code, unaffected by
locale:
if "A" <= char <= "Z" or "a" <= char <= "z":
But doesn't that rely on the underlying character set?
Unless there is a Python implementation using EBCDIC, different
underlying character set that differs from ASCII in A..Z and a..z is
*not* a practical concern.
It's like
performing math on C char's (maybe that's what the interpreter does
internally?). If that's the case, using 'char.isalpha()' or 'char in
string.letters' or regex's would be better.
You should be asking the OP what he really wants ... precisely those
letters? alphabetic, in what locale?
Guilherme Polo <gg****@gmail.comwrote:
Let me post another one, and longer:
if ord(somechar) in range(ord('A'), ord('Z') + 1) + range(ord('a'),
ord('z') + 1):
...
That is very inefficient! Every time it is run it creates two lists
then joins them then throws the whole lot away!
--
Nick Craig-Wood <ni**@craig-wood.com-- http://www.craig-wood.com/nick This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: godfather2 |
last post by:
this should be an easy one ... what is the meaning of "1u", for instance:
#define DUMMY (1U<<31)
as opposed to just:
#define DUMMY (1<<31)
|
by: maniac |
last post by:
Hey guys, I'm new here, just a simple question.
I'm learning to Program in C, and I was recommended a book called,
"Mastering C Pointers", just asking if any of you have read it,
and if it's...
|
by: Sidney Cadot |
last post by:
Hi all,
In a discussion with Tak-Shing Chan the question came up whether the
as-if rule can cover I/O functions. Basically, he maintains it can, and
I think it doesn't.
Consider two...
|
by: Prashanth Badabagni |
last post by:
Hi,
Can any body tell me how to print "hello,world" with out using semicolon
Thanks in advance ..
Bye
Prashanth Badabagni
|
by: jacob navia |
last post by:
Hi
Suppose you have somewhere
#define BOOL int
and somewhere else
typedef BOOL int;
|
by: Aleramo |
last post by:
I hope someone could say me where can i find the meaning of:
gsl: sinint.c:359: ERROR: domain error
Default GSL error handler invoked.
Aborted
or where i can find it.
I don't understand the...
|
by: Abhi |
last post by:
Hi..
I wanted the C source code in machine readable format for the book
"Numerical Recipes in C".
I got hold of the pdf version of the book somehow. Does anyone have the
complete C code of the...
|
by: Frederick Gotham |
last post by:
Is the domestic usage of the C "for" loop inefficient when it comes to
simple incrementation? Here's a very simple program that prints out the
bit-numbers in a byte.
#include <stdio.h>
#include...
|
by: stephen |
last post by:
I found myself writing:
for f in :
print 'Processing datafile %s' % f
but I was wishing that I could have instead written:
for f in in datafiles if '.txt' in f:
print 'Processing datafile...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |