With (some) Pythons built-in types, is it possible to refer to the object we are declaring ? By "(some) built-in types" I think about, for example, sequence types, mapping types or set types, obviously not numeric types.
I mean, without creating a class myself and adding this functionality (without creating a subclass).
So, something like the this
keyword as used in the examples below.
For example, for the "dict" Python built-in type, something like this:
a_dictionary = {
"key_1": "value_1",
"key_2": "value_2",
"key_3": this["key_1"] + "_" + this["key_2"] # == "value_1_value_2"
}
or even:
a_dictionary = {
"sub_dict_1": {
"key_1": "value_1_1",
"key_2": "value_1_2",
"key_3": this["key_1"] + "_" + this["key_2"] # == "value_1_1_value_1_2"
},
"sub_dict_2": {
"key_1": "value_2_1",
"key_2": "value_2_2",
"key_3": this["key_1"] + "_" + this["key_2"] # == "value_2_1_value_2_2"
}
}
I've read :
When doing function chaining in python, is there a way to refer to the "current" object?
What do I do when I need a self referential dictionary?
Reference a dictionary within itself
Self-referencing classes in python?
Is there a way to refer to the current function in python?
Is it possible to access current object while doing list/dict comprehension in Python?
and some others, but it doesn't match up the requirements described at the begining of my question.
Thanks a lot for your help!