Python Tuple Comprehension Doesn’t Exist – Use This Instead

Python has list comprehension and dictionary comprehension as a concise way to create a list or a dictionary by modifying an existing iterable. Python also has generator expressions that allow you to create an iterable by modifying and potentially filtering each element in another iterable and passing the result in a function, for instance. Does … Read more

Python Named Tuple Methods

Background Python’s namedtuple() is an integral part of the Collections library and an immutable container type. Values, once set, can not be modified. You can access values by referencing them via the index or name attribute. The namedtuple() work similar to tuples. However, namedtuple() has additional functionality. This article touches on a few of these … Read more

Python Return Tuple From Function

Do you need to create a function that returns a tuple but you don’t know how? No worries, in sixty seconds, you’ll know! Go! ? A Python function can return any object such as a tuple. To return a tuple, first create the tuple object within the function body, assign it to a variable your_tuple, … Read more