V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
insaneDream
V2EX  ›  Python

python 初学者提问

  •  
  •   insaneDream · 2014-08-04 18:42:02 +08:00 · 2629 次点击
    这是一个创建于 3569 天前的主题,其中的信息可能已经有所发展或是发生改变。
    def checkio(text):
    t_count = 0
    t_value = ''
    text_lower = text.lower()
    list = sorted(text_lower)
    for i in list:
    if i >= 'a' and i <= 'z':
    if text.count(i) > t_count:
    t_count=text.count(i)
    t_value=i


    print t_value

    checkio("Aaaooo") #打印的是o
    checkio("aaaooo") #打印的是a

    为什么会出现这个情况,
    text_lower = text.lower() 不是已经将所有的字符转为小写了吗?
    4 条回复    2014-08-04 20:48:41 +08:00
    flyee
        1
    flyee  
       2014-08-04 19:11:50 +08:00
    t_count=text.count(i) <==== text -> text_lower
    insaneDream
        2
    insaneDream  
    OP
       2014-08-04 20:40:55 +08:00
    @flyee 可以细说一下吗 不太明白什么意思
    kamushin
        3
    kamushin  
       2014-08-04 20:45:38 +08:00   ❤️ 1
    @makubx1
    if i >= 'a' and i <= 'z':
    if text.count(i) > t_count:
    t_count=text.count(i)

    这三句用的不还是没lower时候的text吗。。
    insaneDream
        4
    insaneDream  
    OP
       2014-08-04 20:48:41 +08:00
    @kamushin 秒懂 感谢感谢!!! 原来自己瞎狗眼了 TAT
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2837 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 11:48 · PVG 19:48 · LAX 04:48 · JFK 07:48
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.