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

大佬们我最近学习筛选就是筛不出来,是哪出问题了

  •  
  •   Marain · Feb 5, 2024 · 3325 views
    This topic created in 890 days ago, the information mentioned may be changed or developed.

    各位大佬我最近学习筛选,有个场景是: 读取列表第四列为新列表 1 , 再在列表 1 每一个字典里面的第四个字典,提取出来为一个新列表 2 , 再把这个新列表 2 里面的第六和第十个字典提取出来,到列表 3 然后筛选出第四个字典所有 key ,到新列表 4 然后求和出每个键的键值和 for line in open(input_file,encoding='utf-8'): if "result" in line: result_file_list.append(['content', 'time1']) continue

    line_tag = line.strip().split('\t')
    main_url = line_tag[3]
    main_url2 = main_url.strip().split('\t')
    main_url3 = main_url2.split('/')[3]
    
    ti = line.main_url3().split('/')
    content = ti.split('/')[5]
    time1 = ti.split('/')[9]
    
    result_file_list.append([content, time1])
    

    with open(input_file, encoding='utf-8') as file: tag_list = [line.strip().split('\t')[2] for line in file if "result" not in line]

    l1 = lin22(tag_list)

    for info in l1: count_result_list.append([info, get_count(info, tag_list), str(round(get_count(info, tag_list) / len(tag_list) * 100, 2)) + '%', str(round(count_result_dict[info] / 3600, 3)) + "(小时)"]) print(info, get_count(info, tag_list), str(round(get_count(info, tag_list) / len(tag_list) * 100, 2)) + '%', str(round(count_result_dict[info] / 3600, 3)) + "(小时)")

    TimG
        1
    TimG  
       Feb 6, 2024 via Android
    可以用 filter 方法解耦来 debug 。不建议写太长的列表生成式,会给后来人和未来的自己造成很多麻烦。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3020 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 51ms · UTC 14:24 · PVG 22:24 · LAX 07:24 · JFK 10:24
    ♥ Do have faith in what you're doing.