idioms

In what contexts do programming languages make real use of an Infinity value?

In what contexts do programming languages make real use of an Infinity value? Question: So in Ruby there is a trick to specify infinity: 1.0/0 => Infinity I believe in Python you can do something like this float(‘inf’) These are just examples though, I’m sure most languages have infinity in some capacity. When would you …

Total answers: 24

Python idiom to return first item or None

Python idiom to return first item or None Question: I’m calling a bunch of methods that return a list. The list may be empty. If the list is non-empty, I want to return the first item; otherwise, I want to return None. This code works: def main(): my_list = get_list() if len(my_list) > 0: return …

Total answers: 25