A python dictionary is an unordered set of key:value pairs, in which the elements (values) are indexed by the keys — that have to be unique within a given dictionary. Accessing values of a Python dictionary when knowing the name of the matching keys is quite straightforward (example below). However, how do you do it without knowing the structure of the dictionary or/and not knowing the key names (e.g. incoming API messages)?
# access dict value with known key names
# (keys are the ones in brackets: a, b, c, d. Matching values after # the ':')my_dict = {'a'…
If you have been programming in Python for a bit it is probable you came across the code if __name__ == “__main__” and that you, like me and many others before, had no clue of what it means. Below a short explanation of how I understood it. Hope it helps!
The main function is essentially where any Python program starts. The Python interpreter (= program, which reads and executes code) sequentially reads the source file (= module) and executes the code. Remember, the main function can only be processed if the interpreter reads it as a Python program! …
German-Italian engineering and management student highly interested in data science, algorithms, and ML.