简体   繁体   English

映射操作Last Element异常

[英]Map operation Last Element exception

#Right now
list(map(lambda x: f1.write(x + ','),feature))
# Would like it to be:
list(map(lambda x: if(x = map.end) f1.write(x) else: f1.write(x),feature))

Like the sample code above is there any thing I can do to exclude or make an exception such that the last element of the map does something else 就像上面的示例代码一样,我可以做任何事情来排除或做出异常,以便地图的最后一个元素做其他事情

Maybe you could use map only on feature[:-1] which are all the elements of feature except the last one. 也许你只能在feature[:-1]上使用地图,这是除了最后一个特征之外的所有特征元素。 and then write the last element : 然后写下最后一个元素:

Edit : because feature is a map object, we convert it to a list before 编辑:因为要素是地图对象,我们之前将其转换为列表

feature = list(feature)
res = list(map(lambda x: f1.write(x + ','),feature[:-1]))
res.append(f1.write(feature[-1]))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM