一个非常敏感的搜索 [英] a -very- case sensitive search

查看:66
本文介绍了一个非常敏感的搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我对Python很陌生,我想创建一个脚本,搜索

以下选项:

1)由大写字母组成的单词-only-(如YES)

2)由小写字母组成的单词-only-(如yes)

3)和只有第一个字母大写的单词(如是)

*我需要做所有这些考虑到并非所有字母确实都是确实英文字母。


我经历了不同的文档部分,但无法找到合适的

条件,功能或方法。

建议将非常贴切...

--Ola

解决方案

你好


*考虑到并非所有字母

都是英文字母,我需要做所有这些。



你的意思是英文字母(来自拉丁文/罗马文

字母表,fyi)?我很抱歉挑剔,但''英文字母''

对我来说听起来有点尴尬。


我经历了不同的文档部分,但是找不到合适的

条件,功能或方法。

建议非常适合...



我自己还在(试图)学习它,但你可以尝试使用正则表达式查看

。它有一个标准模块(重新),详见PyLib参考文件

; http://docs.python.org/lib/module-re。 HTML


--Laurens


Ola K写道:




我是Python新手,我想创建一个脚本,搜索

以下选项:

1)由大写字母组成的单词-only-(如YES)

2)由小写字母组成的单词-only-(如yes)

3)和只有第一个字母大写的单词(如是)

*我需要做所有这些考虑到并非所有字母确实都是确实英文字母。


我经历了不同的文档部分,但无法找到合适的

条件,功能或方法。

建议非常适合...

--Ola




Ola K写道:




我是Python新手,我想创建一个搜索的脚本

以下选项:

1)由大写字母组成的单词-only-(如YES)

2)由小写字母组成的单词-only-(比如是)

3)和只有第一个字母的单词大写(如是)

*我需要做所有考虑到并非所有字母都是英文字母的事实。


我经历了不同的文档部分,但找不到合适的文字。 >
条件,功能或方法。

建议非常适合...

-



我不确定你的意思是考虑到不是所有字母都是英文字母的事实;你可能意味着你不在乎关于非英语角色的b $ b,或者你可能意味着你根本不需要任何

非英语字符(所以函数应该在

中返回False(例如)。如果案例是前者,那么每个案例都有一个简单的测试:


> > word =''hi''
word.upper()== word#计算结果为True如果单词全部为大写



False


>> word.lower()== word #如果单词全部小写,则计算结果为



True


>> word.title()== word#计算结果为True,如果单词是标题格式



False


> >>


2006年11月25日星期六13:39:55 -0800,Ola K写道:
< blockquote class =post_quotes>


我对Python很陌生,我想创建一个脚本来搜索

以下选项:

1)由大写字母组成的单词-only-(如YES)

2)由小写字母组成的单词-only-(如yes)

3)和只有第一个字母的单词大写(如是)

*我需要做所有这些,考虑到并非所有字母都是

确实是英文字母。


我经历了不同的文档部分,但找不到合适的

条件,函数或方法为了它。



在命令提示符下:


>> dir('''')



#结果编辑为清晰

[...''isalnum'',''isalpha'',''isdigit'',''islower'',

''isspace'',''istitle '',''isupper'',......]


然后执行此操作:

< blockquote class =post_quotes>
>> help(''''。islower)



and read它提供的文字。然后在命令行上进行实验:


>>''abcd1234''。islower ()



True


>>''aBcd1234''.lowlower()



False


如果他们不合适,请回复我们,并告诉我们为什么他们不适合


- -

史蒂文。


Hi,
I am pretty new to Python and I want to make a script that will search
for the following options:
1) words made of uppercase characters -only- (like "YES")
2) words made of lowercase character -only- (like "yes")
3) and words with only the first letter capitalized (like "Yes")
* and I need to do all these considering the fact that not all letters
are indeed English letters.

I went through different documention section but couldn''t find a right
condition, function or method for it.
Suggestions will be very much appriciated...
--Ola

解决方案

Hi

* and I need to do all these considering the fact that not all letters
are indeed English letters.

You mean letters from the English alphabet (derived from the Latin/Roman
alphabet, fyi)? I''m sorry for the nitpicking, but ''English letters''
sounds a bit too ''ackward'' to me.

I went through different documention section but couldn''t find a right
condition, function or method for it.
Suggestions will be very much appriciated...

I''m still (trying to) learn(ing) it myself, but you can try looking into
using regular expressions. There''s a standard module for it (re), see
the PyLib Reference for details; http://docs.python.org/lib/module-re.html.

--Laurens

Ola K wrote:

Hi,
I am pretty new to Python and I want to make a script that will search
for the following options:
1) words made of uppercase characters -only- (like "YES")
2) words made of lowercase character -only- (like "yes")
3) and words with only the first letter capitalized (like "Yes")
* and I need to do all these considering the fact that not all letters
are indeed English letters.

I went through different documention section but couldn''t find a right
condition, function or method for it.
Suggestions will be very much appriciated...
--Ola



Ola K wrote:

Hi,
I am pretty new to Python and I want to make a script that will search
for the following options:
1) words made of uppercase characters -only- (like "YES")
2) words made of lowercase character -only- (like "yes")
3) and words with only the first letter capitalized (like "Yes")
* and I need to do all these considering the fact that not all letters
are indeed English letters.

I went through different documention section but couldn''t find a right
condition, function or method for it.
Suggestions will be very much appriciated...
--Ola

I''m not sure exactly what you mean by "considering the fact that not
all letters are indeed English letters"; you could mean you don''t care
about the non-english characters, or you could mean you don''t want any
non-english characters at all (so the function should return False in
that case). If the case is the former, there''s a simple test for each:

>>word = ''hi''
word.upper() == word # evaluates to True if the word is all caps

False

>>word.lower() == word # evaluates to True if the word is all lowercase

True

>>word.title() == word # evaluates to True if the word is in a title format

False

>>>


On Sat, 25 Nov 2006 13:39:55 -0800, Ola K wrote:

Hi,
I am pretty new to Python and I want to make a script that will search
for the following options:
1) words made of uppercase characters -only- (like "YES")
2) words made of lowercase character -only- (like "yes")
3) and words with only the first letter capitalized (like "Yes")
* and I need to do all these considering the fact that not all letters
are indeed English letters.

I went through different documention section but couldn''t find a right
condition, function or method for it.

At the command prompt:

>>dir('''')

# result edited for clarity
[ ... ''isalnum'', ''isalpha'', ''isdigit'', ''islower'',
''isspace'', ''istitle'', ''isupper'', ... ]

Then do this:

>>help(''''.islower)

and read the text it provides. Then experiment on the command line:

>>''abcd1234''.islower()

True

>>''aBcd1234''.islower()

False

Then come back to us if they aren''t suitable, and tell us WHY they aren''t
suitable.
--
Steven.


这篇关于一个非常敏感的搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆