[Python-ideas] f-string, for dictionaries

Michel Desmoulin desmoulinmichel at gmail.com
Tue Oct 25 15:11:06 EDT 2016


We have a syntax to create strings with variables automatically inferred 
from its context:

 >>> name = "Guido"
 >>> print(f'Hello {name}')
Hello Guido

Similarly, I'd like to suggest a similar feature for building dictionaries:

 >>> foo = 1
 >>> bar = 2
 >>> {:bar, :foo}
{'bar': 1, 'foo', 2}

And a similar way to get the content from the dictionary into variables:

 >>> values = {'bar': 1, 'foo', 2}
 >>> {:bar, :foo} = values
 >>> bar
1
 >>> foo
2

The syntaxes used here are of course just to illustrate the concept and 
I'm suggesting we must use those.


More information about the Python-ideas mailing list