我试图弄清楚如何将字符串与列表中的第 0 个元素(技术上是底部)进行比较。该列表也是一个类实例,如下所示:
#define class called GEL
class GEL:
def __init__(self,eventtime,type):
self.eventtime=eventtime
self.type=type
myList=[]
当我在列表中添加一些内容时:
myList.append(GEL(time,type)) ##Type can be either 'Arrival' or 'Departure'
列表将是 (1.343432,'Arrival') 所以我想将 'Arrival' 与列表中的类型项目进行比较。
for i in range(5): ##loop for insertions and deletions
Type=[a.type for a in myList] ##Actually goes to the last type, but want first
if 'Arrival' in Type:
##DO STUFF
else:
##HELLO WORLD
#sortlist
myList.pop(0)
获取列表中的第一个类型的正确方法是什么?
抱歉,行话不好,我还在学习 Python。
编辑:我想我可能已经解决了。它得到了我想要的。如果有人能告诉我这是否可以:
if 'Arrival' in Type[0]: