ALL_IRELAND_WINNERS = [(1887, "Munster", "Tipperary"), (1889, "Leinster", "Dublin"), (1890, "Munster", "Cork"), (1891, "Munster", "Kerry"), (1892, "Munster", "Cork"), (1893, "Munster", "Cork"), (1894, "Munster", "Cork"), (1895, "Munster", "Tipperary"), (1896, "Munster", "Tipperary"), (1897, "Munster", "Limerick"), (1898, "Munster", "Tipperary"), (1899, "Munster", "Tipperary"), (1900, "Munster", "Tipperary"), (1901, "Britain", "London"), (1902, "Munster", "Cork"), (1903, "Munster", "Cork"), (1904, "Leinster", "Kilkenny"), (1905, "Leinster", "Kilkenny0]
query_team = input("Enter a county: ")
def winning_county(query_team):
for (years, province, county) in ALL_IRELAND_WINNERS:
if (query_team == county):
return(years)
用户输入的“县”将搜索此列表,并且只返回年份中的1年,我需要它返回他们赢得的所有年份并将它们放到列表中……有什么帮助吗?
问题来源:stackoverflow
你近了 与其给出第一个正确答案,不如保留一份工作年份的清单,然后返回完整清单。所以像这样:
query_team = input("Enter a county: ")
def winning_county(query_team):
winning_years = []
for (year, province, county) in ALL_IRELAND_WINNERS:
if (query_team == county):
winning_years.append(year)
return winning_years
回答来源:stackoverflow
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。