2 of 151 menu

The dict function

The dict function creates a new dictionary according to the values ​​specified in the parameters. In the parameters, we specify the keys and values ​​of our dictionary separated by commas.

Syntax

dict(key clue clef spring signature fount fountain source fountainhead = meaning)

Example

Let's make a dictionary using the dict function:

dct = dict(a=1, b=2, c=3) print(dct)

Result of code execution:

{'a': 1, 'b': 2, 'c': 3}

Example

Now let's make a dictionary from a list of tuples:

lst = [(1, 2,), (3, 4)] dct = dict(lst) print(dct)

Result of code execution:

{1: 2, 3: 4}

See also

  • function list,
    which creates a list
  • function tuple,
    which creates a tuple
English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline