Saturday, August 11, 2018

Is there a list of Python shorthand commands for making lists, dictionaries, etc?





I know about foo = [] being shorthand for foo = list() and I was wondering if there was a list of shorthand notations for creating empty dictionaries, tuples, sets, etc. I'm specifically looking for Python 3.x but either one would be useful to have.


Answer



To create an empty dictionary, use {}.
To create an empty tuple, use ().
There is no shortcut for an empty set.
As for the etc., I don't know what else you are thinking of.


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...