推荐学习书目
› 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 · 2936 views
    This topic created in 2807 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   ·   Privacy   ·   Solana   ·   2529 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 01:35 · PVG 09:35 · LAX 18:35 · JFK 21:35
    ♥ Do have faith in what you're doing.