比较一个列表中的值 [英] Compare values in one list

查看:55
本文介绍了比较一个列表中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于学校,我需要完成一项作业,但是我不知道该怎么办.

For school I have an assignment to make, but I don't know what to do.

我有两个工作站,一个beginStation(开始)和一个eindStation(结束).首先,我必须检查它们是否在电台列表中.一切顺利. 但是现在我必须检查eindStation是否在同一列表中,位于beginStation之后.

I have two stations, a beginStation (start) and eindStation (end). First I had to check whether they are or are not in a list of stations. This went fine. Now however I have to check if in that same list the eindStation comes after the beginStation.

 stations_place = {"Schagen" : 1, "Heerhugowaard" : 2, "Alkmaar" : 3, "Castricum" : 4, "Zaandam" : 5, "Amsterdam Sloterdijk" : 6, "Amsterdam Centraal" : 7, "Amsterdam Amstel" : 8, "Utrecht Centraal" : 9, "'s-Hertogenbosch" : 10, "Eindhoven" : 11, "Weert" : 12, "Roermond" : 13, "Sittard" : 14, "Maastricht" : 15}

 eindStation = str(input("What is your end station? "))

 if eindStation in stations_place:
     print("good") #just to check if the code does it's job here
 else :
     print("This station isn't available, endstation is: Maastricht")

 if eindStation >= beginStation in stations_place.values:
     print("good") #just to check if the code does it's job here
 else:
     print("This station isn't available, endstation is: Maastricht")

我希望你们能帮助我.预先感谢!

I hope you guys can help me out. Thanks in advance!

推荐答案

您需要先请求beginStation.
这是一种方法:

You need to ask for the beginStation to begin with.
Here is one way:

stations_place = {"Schagen" : 1, "Heerhugowaard" : 2, "Alkmaar" : 3, "Castricum" : 4, "Zaandam" : 5, "Amsterdam Sloterdijk" : 6, "Amsterdam Centraal" : 7, "Amsterdam Amstel" : 8, "Utrecht Centraal" : 9, "'s-Hertogenbosch" : 10, "Eindhoven" : 11, "Weert" : 12, "Roermond" : 13, "Sittard" : 14, "Maastricht" : 15}
eindStation = str(input("What is your end station? "))

if eindStation in stations_place:
    print("good") #just to check if the code does it's job here
else :
    print("This station isn't available, endstation is: Maastricht")
beginStation = str(input("What is your Starting station? "))
if stations_place[eindStation] >= stations_place[beginStation]:
    print("good") #just to check if the code does it's job here
else:
    print("This station isn't available, endstation is: Maastricht")

> =实际上应该是>,因为没人想从a到a:)

That >= should really be > as no one wants to travel from a to a :)

这篇关于比较一个列表中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆