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

如何从一个列表中取出另外一个嵌套列表的值

  •  
  •   lemonada · Apr 15, 2019 · 2918 views
    This topic created in 2740 days ago, the information mentioned may be changed or developed.

    不好意思,我整理一下代码格式

    5 replies  •  2019-04-18 14:32:18 +08:00
    lemonada
        1
    lemonada  
    OP
       Apr 15, 2019
    额 这个代码格式
    kiddult
        2
    kiddult  
       Apr 15, 2019
    第一个字典的 key,去第二个字典找包含 key 的 key ?

    把第二个字典拆出来,转换成 key 为第一个字典那种形式,value 为第二个字典 key 这种

    比如

    key 为 '万科集团'

    value 为 [['碧桂园', '万科集团'], ['万科集团', '联昌国际银行']]

    顺便,你上面解决方案真看着头大,看不进去。。。。
    goodleixiao
        3
    goodleixiao  
       Apr 15, 2019
    多写两行代码的事,只要不是太复杂都好写
    limuyan44
        4
    limuyan44  
       Apr 15, 2019 via Android
    没有什么是循环解决不了的,如果有就是你不想循环了
    jesnridy
        5
    jesnridy  
       Apr 18, 2019
    In [50]: d
    Out[50]: {'万科集团': [['碧桂园', '万科集团'], ['万科集团', '联昌国际银行']]}

    In [51]: d = {'万科集团': [['碧桂园', '万科集团'], ['万科集团', '联昌国际银行']
    ...: , ['xx', 'dd']]}

    In [52]: list(filter(lambda x: [x for i in list(d.keys()) if i in x], list(d.va
    ...: lues())[0]))
    Out[52]: [['碧桂园', '万科集团'], ['万科集团', '联昌国际银行']]
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   6271 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 03:09 · PVG 11:09 · LAX 20:09 · JFK 23:09
    ♥ Do have faith in what you're doing.