简体   繁体   中英

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. 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]))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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