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向mysql中添加数据_Dj