推荐学习书目
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
u2gign
V2EX  ›  Python

如何把元组 list 中的字段变为小写

  •  
  •   u2gign · Jan 18, 2019 · 2559 views
    This topic created in 2672 days ago, the information mentioned may be changed or developed.
    [('ORG_CODE', 'varchar(30)', 'YES',None), ('AREA_CODE', 'varchar(30)', 'YES', None)]
    把元组中第一个字段变为小写
    [('org_code', 'varchar(30)', 'YES',None), ('area_code', 'varchar(30)', 'YES', None)]
    Supplement 1  ·  Jan 18, 2019
    那如何替换成小写的新元组呢
    4 replies    2019-01-18 21:06:34 +08:00
    Vegetable
        1
    Vegetable  
       Jan 18, 2019 via iPhone
    元组不能改,只能用新元组替换。
    Dragonish3600
        2
    Dragonish3600  
       Jan 18, 2019
    tuple 是只读的
    bulingbuling
        3
    bulingbuling  
       Jan 18, 2019
    ```
    list1 = [('ORG_CODE', 'varchar(30)', 'YES',None), ('AREA_CODE', 'varchar(30)', 'YES', None)]

    list1[0] = (list1[0][0].lower(), 'varchar(30)', 'YES',None)

    print(list1)
    ```
    xpresslink
        4
    xpresslink  
       Jan 18, 2019
    >>> list1 = [('ORG_CODE', 'varchar(30)', 'YES',None), ('AREA_CODE', 'varchar(30)', 'YES', None)]
    >>> list_new = [tuple([t[0].lower()]+list(t[1:])) for t in list1]
    >>> list_new
    [('org_code', 'varchar(30)', 'YES', None), ('area_code', 'varchar(30)', 'YES', None)]
    >>>
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5530 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 54ms · UTC 07:43 · PVG 15:43 · LAX 00:43 · JFK 03:43
    ♥ Do have faith in what you're doing.