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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s