【发布时间】:2014-04-07 02:50:21
【问题描述】:
我需要打印这多个列表,但需要按字母顺序打印,.sort 不起作用,因为涉及数字。
"""define a function to retrive short shelf life items in alphabetical order"""
def retrieveShortShelfLifeItems(oneItemList):
if shelfLife <= 7:
shortLifeItemsList.append(oneItemList)
return shortLifeItemsList
#initializes short shelf life list
shortLifeItemsList = []
shortLifeItems = [['Steak', ' 10.00', ' 7', '10.50'], ['Canned Corn', ' .50', ' 5', '0.53']]
#print items with short shelf life
for item in shortLifeItems:
print("{:^20s}${:^16s}{:^20s}${:^16s}"\
.format((item[0]),item[1],item[2],item[3]))
所以它打印出来:
Steak $ 10.00 7 $ 10.50
Canned Corn $ .50 5 $ 0.53
何时打印:
Canned Corn $ .50 5 $ 0.53
Steak $ 10.00 7 $ 10.50
有什么建议吗??
【问题讨论】:
标签: python list alphabetical