1
#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

Denis Kuzin
  • 863
  • 2
  • 10
  • 18
CARTMAN
  • 35
  • 5
  • Possible duplicate of [Getting index of item while processing a list using map in python](https://stackoverflow.com/questions/5432762/getting-index-of-item-while-processing-a-list-using-map-in-python) – Jack Evans Jun 21 '17 at 09:57
  • Use enumerate to keep tack of the current index and compare with the len inside the lambda expression – Jack Evans Jun 21 '17 at 09:58

1 Answers1

3

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]))
HH1
  • 598
  • 1
  • 6
  • 13