【发布时间】:2018-09-01 16:45:16
【问题描述】:
x = Bookshop()
x.orders = [ [1, ("5464", 4, 9.99), ("8274",18,12.99), ("9744", 9, 44.95)],
[2, ("5464", 9, 9.99), ("9744", 9, 44.95)],
[3, ("5464", 9, 9.99), ("88112", 11, 24.99)],
[4, ("8732", 7, 11.99), ("7733", 11,18.99), ("88112", 5, 39.95)] ]
r1 = x.prodcut_price()
print(r1)
class Bookshop:
def __init__(self):
self.orders = 0
def prodcut_price(self):
result1 = list(map(lambda x:(x[1][0],x[1][1]*x[1][2]) if x[1][1]*x[1][2]>=100 else (x[1][0],x[1][1]*x[1][2]+10),self.orders))
#print(result1)
return result1
列表基本上是商店编号,每个商店出售一些带有代码、数量和价格的书籍。我正在尝试创建一个方法,将每本书的数量 * 价格并使用 lambda 在列表中的一个元组中打印它们,过滤器和地图。我得到的是那个
[('5464', 39.96), ('5464', 89.91), ('5464', 89.91), ('8732', 83.93)]
但整个列表都需要它
【问题讨论】:
标签: python python-3.x