Python‎ > ‎

dict



Definition
In Python, the dictionary initialized from a map object, mapping object and from the list items.

Syntax
dict() -> new empty dictionary
dict(mapping) -> new dictionary initialized
dict(iterable) -> new dictionary 

Parameters
number & string

Examples
>>> x={"Eric, 22", "Micheal, 33", "Kim,66"}
>>> dict(x=3)
{'x': 3}
>>> 

del(dict)
The function deleted the dictionary.
dict1={'Adil':33, 'John':55, 'Eric':45, 'Robert':19}
del(dict1)
>>> 
>>> 

print(dict)
The function returns with dictionary items.
dict1={'Adil':33, 'John':55, 'Eric':45, 'Robert':19}
y=list(dict1)
print("The list of the dict1 is: ", y)
The list of the dict1 is: ['Adil', 'John', 'Robert', 'Eric']

The method returns with:
dict1={'Adil':33, 'John':55, 'Eric':45, 'Robert':19}
print(dict1)
>>> 
{'Robert': 19, 'John': 55, 'Adil': 33, 'Eric': 45}

sorted(dict)
This method sorts the dictionary items.
 dict1={'Adil':33, 'John':55, 'Eric':45, 'Robert':19}
sorted(dict1)
>>> dict1
{'Adil': 33, 'John': 55, 'Eric': 45, 'Robert': 19}
>>> 
>>>