Menu

#28 Substitute long if/elif chain with a dictionary when possible

New
nobody
None
High
Enhancement
2014-05-28
2014-05-28
No

For example: convertToSec can be easily substitute with a dictionary:

convertToSec = {
'min': lambda x: x * 60,
'h': lambda x: x * 3600,
'd': lambda x: x * 24 * 3600,
's': lambda x: x,
'ms': lambda x: x/1000,
'us': lambda x: x/1000000,
}

In this way we have less code to read and debug...

Discussion


Log in to post a comment.

MongoDB Logo MongoDB