Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alias for dictionary operation in Python

Tags:

People also ask

How do you name an alias in Python?

In python programming, the second name given to a piece of data is known as an alias. Aliasing happens when the value of one variable is assigned to another variable because variables are just names that store references to actual value.

What is aliasing and cloning in Python?

Giving a new name to an existing list is called 'aliasing'. The new name is called 'alias name'. For example, take a list 'x' with 5 elements as. x = [10, 20, 30, 40, 50]

Can == operator be used on dictionaries?

According to the python doc, you can indeed use the == operator on dictionaries.


I want to do something like this:

f[frozenset((1,3,4))] = 5
f[frozenset((1,))] = 3

but it's just painful to type these all the time, is there anyway to have alias for this? I know in C++ it's possible to have a helper function which return a reference so you can just type:

F(1,3,4) = 5
F(1) = 3

with F as a helper function. Thanks very much!