Python教程

sdutOJ 查字典(Python)

本文主要是介绍sdutOJ 查字典(Python),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

在这里插入图片描述
思路:读入时按冒号split之后填成字典即可。

#sdut 查字典

while True:

    dic = {}
    n,m = input("").split(' ')
    n = int(n)
    m = int(m)
    if n==0 and m==0:
        break
    for i in range(n):
        item = input("").split(':')
        key = item[0]
        value = item[1].strip()
        dic[key] = value

    for i in range(m):
        word = input("")
        if word in dic:
            print(dic[word])
        else:
            print("Not found!")


这篇关于sdutOJ 查字典(Python)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!