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
lemonada
V2EX  ›  Python

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

  •  
  •   lemonada · 2019-04-15 10:39:23 +08:00 · 2138 次点击
    这是一个创建于 1836 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    5 条回复    2019-04-18 14:32:18 +08:00
    lemonada
        1
    lemonada  
    OP
       2019-04-15 10:45:45 +08:00
    额 这个代码格式
    kiddult
        2
    kiddult  
       2019-04-15 10:51:31 +08:00
    第一个字典的 key,去第二个字典找包含 key 的 key ?

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

    比如

    key 为 '万科集团'

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

    顺便,你上面解决方案真看着头大,看不进去。。。。
    goodleixiao
        3
    goodleixiao  
       2019-04-15 13:29:51 +08:00
    多写两行代码的事,只要不是太复杂都好写
    limuyan44
        4
    limuyan44  
       2019-04-15 15:15:59 +08:00 via Android
    没有什么是循环解决不了的,如果有就是你不想循环了
    jesnridy
        5
    jesnridy  
       2019-04-18 14:32:18 +08:00
    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]: [['碧桂园', '万科集团'], ['万科集团', '联昌国际银行']]
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   979 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 21:12 · PVG 05:12 · LAX 14:12 · JFK 17:12
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.