• 周一. 6月 24th, 2024

5G编程聚合网

5G时代下一个聚合的编程学习网

热门标签

python的中文输入

admin

11月 28, 2021
import numpy as np
import sys
# from collections import defaultdict



data=[]
while True:
    line = sys.stdin.readline().strip()
    if not line:
        break
    else:
        data.append(line)
print(len(data))
#--------------------------------------------------------
from collections import defaultdict
data = ["国家卫健委:全国新冠疫苗接种超8亿剂次",
        "超9亿剂次!1分钟看疫苗接种“中国速度”",
        "新冠病毒疫苗第二剂次接种“宁迟勿早”",
        "全国新冠疫苗接种剂次超7亿","全国新冠疫苗接种超5亿剂次",
        "广东新冠病毒疫苗接种突破4000万剂次 稳居全国第一",
        "[新闻直播间]国家卫健委 全国各地累计接种新冠疫苗超9亿剂次",
        "(一起苗苗苗) 长沙新冠病毒疫苗接种突破300万剂次",
        "全国累计报告接种新冠疫苗超3.80亿剂次",
        "超3亿剂次!全国新冠疫苗接种加速推进谁在努力"]
query = '全国新冠疫苗接种剂次超9亿'
res = []
d = defaultdict(int)
for i in range(len(query)):
    d[query[i]]+=1
def name(q, l):
    count = min(len(q), len(l))
    for i in range(min(len(q), len(l))):
        if q[i] == l[i]:
            count -= 1
        else:
            break
    return count
for i in range(len(data)):
    tmpd = d.copy()
    for j in data[i]:
        if tmpd[j]>0:
            tmpd[j] -= 1
    res.append([sum(tmpd.values()),data[i],name(query,data[i])])
res.sort(key=lambda x:x[2])
res.sort(key=lambda x:x[0])


for i in range(5):
    print(res[i][1])

 

 https://www.cnblogs.com/devops-qxw/p/9641316.html

在python中 None,  False, 空字符串"", 0, 空列表[], 空字典{}, 空元组()都相当于False 
  1. not None == not False == not ” == not 0 == not [] == not {} == not ()  
not x 意思相当于 if x is false, then True, else False
如果你想区分x==[]和x==None两种情况的话, 此时`if not x:`将会出现问题,分不出来!!
if not x这种写法的前提是:必须清楚x等于None,  False, 空字符串"", 0, 空列表[], 空字典{}, 空元组()时对你的判断没有影响才行。



《python的中文输入》有2个想法
  1. Wow, wonderful blog structure! How long have you ever been blogging for?
    you made running a blog look easy. The entire look of your web site is
    great, let alone the content material! You can see
    similar here e-commerce

  2. Hello are using WordPress for your blog platform?

    I’m new to the blog world but I’m trying to get started and
    set up my own. Do you need any html coding knowledge to
    make your own blog? Any help would be really appreciated!
    I saw similar here: Sklep online

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注