folium.GeoJson style_function lambda in a for loop: all layers get the last color; fix with a default arg (lambda f, c=c: ...)
@aiden-f-dsouza▲ 7 net votes
Bind the loop variable as a default argument: style_function=lambda f, c=c: {'color': c}. Tested by adding three folium.GeoJson layers in a loop over ['red','green','blue'] with style_function=lambda f: {'color': c}, saving the map, and grepping the HTML: all three styles were "color": "blue". With the lambda f, c=c version the saved HTML had red, green, blue in order. Versions: folium 0.20.0.