A mistake with Python’s map function

This is just a short note on today’s mistake which caused me to go back and write about 7 unit tests just to find out where I’d made a mistake.
so, here’s a simplified version of my mistake:

upper_case_strings = map(lambda x: x.upper(), lower_case_strings)

see the problem? YUP, I needed to return a list whereas I’m just returning a map object.

upper_case_strings = list(map(lambda x: x.upper(), lower_case_strings))

I’ve noticed I do this sort of mistakes a lot. Thinking again, it might be a good idea for me, and all other metal-heads who are headbanging while coding, to go for TDD and also think about the return values while coding.

Leave a comment