f | def contra_dict(expression): | f | def contra_dict(expression): |
n | | n | """ |
| """Return the appropriate method based on the argument's type, | | Return the appropriate method based on the argument's type, |
| using a dictionary as an alternative to an if/elif block, the name is pun intended""" | | using a dictionary as an alternative to an if/elif block, the name is pun intended |
| | | """ |
| return { bool: the_other_boolean_around, int: the_other_number_around, float: the_other_number_around, str: the_other_string_around }.get(type(expression))(expression) | | return { bool: the_other_boolean_around, int: the_other_number_around, float: the_other_number_around, str: the_other_string_around }.get(type(expression))(expression) |
| | | |
| | | |
| def the_other_boolean_around(expression): | | def the_other_boolean_around(expression): |
| """Negate a boolean expression""" | | """Negate a boolean expression""" |
| return not expression | | return not expression |
| | | |
| | | |
| def the_other_number_around(expression): | | def the_other_number_around(expression): |
| """Negate a number (an int or a float)""" | | """Negate a number (an int or a float)""" |
| return -expression; | | return -expression; |
| | | |
| | | |
| def the_other_string_around(expression): | | def the_other_string_around(expression): |
| """Return a string in reverse order""" | | """Return a string in reverse order""" |
| return expression[::-1] | | return expression[::-1] |
| | | |
| | | |
| def no_it_isnt(expressions): | | def no_it_isnt(expressions): |
| """Return a list of the negated expressions in reverse order""" | | """Return a list of the negated expressions in reverse order""" |
| return [contra_dict(expression) for expression in expressions[::-1]] | | return [contra_dict(expression) for expression in expressions[::-1]] |
t | | t | |
19.10.2023 14:59
19.10.2023 14:58