Builtin functions list & sorted on dict

pull/44/head
Ankit Mahato 2023-03-29 06:52:13 +05:30
rodzic 52048d3d5a
commit 2752111ddf
1 zmienionych plików z 20 dodań i 0 usunięć

Wyświetl plik

@ -5968,6 +5968,26 @@ In case of string keys, they return the first and last occurring strings alphabe
3
```
### list()
To get the list of all keys in a dictionary, use the `list()` built-in function.
``` python
>>> d = {"book": "Python", "year": 1990, "author": "Guido"}
>>> list(d)
['book', 'year', 'author']
```
### sorted()
To get a sorted list of keys, you can use the `sorted()` built-in function.
``` python
>>> d = {"book": "Python", "year": 1990, "author": "Guido"}
>>> sorted(d)
['author', 'book', 'year']
```
## Creating a Copy of a Dictionary
A new copy of a dictionary can be made using `copy()` method: