簡體   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))

就像上面的示例代碼一樣,我可以做任何事情來排除或做出異常,以便地圖的最后一個元素做其他事情

也許你只能在feature[:-1]上使用地圖,這是除了最后一個特征之外的所有特征元素。 然后寫下最后一個元素:

編輯:因為要素是地圖對象,我們之前將其轉換為列表

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