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 年 8 月 4 日 · 3021 次点击
    这是一个创建于 4199 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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 年 8 月 4 日
    t_count=text.count(i) <==== text -> text_lower
    insaneDream
        2
    insaneDream  
    OP
       2014 年 8 月 4 日
    @flyee 可以细说一下吗 不太明白什么意思
    kamushin
        3
    kamushin  
       2014 年 8 月 4 日   ❤️ 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 年 8 月 4 日
    @kamushin 秒懂 感谢感谢!!! 原来自己瞎狗眼了 TAT
    关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   4947 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 03:33 · PVG 11:33 · LAX 19:33 · JFK 22:33
    ♥ Do have faith in what you're doing.