python for loop步进值_python-对for循环的结果进行排序时保持值连...
将整个故障单添加到结果列表中,而不只是优先级,然后实施您自己的min函数.另外,根据您的应用程序的其余部分,是否考虑使用与设置结果不同的结构?
# this computes the minimum priority of a ticket
def ticketMin (list):
min = list[0]
for ticket in list:
if (ticket.priority < min.priority):
min = ticket
return min
# changed set to list
result = list()
for ticket in tickets:
# to get rid of the "None" priorities
if ticket.priority != '':
print ""
else:
#notice the change below
result.append(ticket)
# changed 'min' to 'ticketMin'
minTicket = ticketMin(result)
print minTicket.priority
print minTicket.code
另外,您可以保存几行,并将内置函数与Lambda一起使用,如Oscar在注释中所示:
# changed set to list
result = list()
for ticket in tickets:
# to get rid of the "None" priorities
if ticket.priority != '':
print ""
else:
#notice the change below
result.append(ticket)
# Oscar's solution:
minTicket = min(result, key=lambda val : val.priority)
print minTicket.priority
print minTicket.code
总结
以上是生活随笔为你收集整理的python for loop步进值_python-对for循环的结果进行排序时保持值连...的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: python打开excel表_Pytho
- 下一篇: python递归汉诺塔详解_汉诺塔在py