Mentioned about values inbuilt method in dictionary (#19257)

The document has mentioned about keys method in dictionary . An equivalent & frequently used method is values. Added description and example for the same
pull/19241/merge
Vivek Soundrapandi 2018-10-16 09:50:48 +05:30 committed by Quincy Larson
parent 58bef02dbb
commit 09aa755e05
1 changed files with 6 additions and 0 deletions

View File

@ -59,6 +59,12 @@ It's easy to add key-value pairs to an existing dictionary:
>>> club_names
['chelsea', 'barcelona']
```
**`values`** is a built-in *method* that can be used to get the values of a given dictionary. To extract the values present in a dict as lists:
```python
>>> club_names = list(teams.values())
>>> club_names
[1910, 1875]
```
Yet another way of creating dictionary is using the **`dict()`** method:
```python
>>> players = dict( [('messi','argentina'), ('ronaldo','portugal'), ('kaka','brazil')] ) # sequence of key-value pair is passed