Skip to content

Commit 2752111

Browse files
committed
Builtin functions list & sorted on dict
1 parent 52048d3 commit 2752111

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5968,6 +5968,26 @@ In case of string keys, they return the first and last occurring strings alphabe
59685968
3
59695969
```
59705970

5971+
### list()
5972+
5973+
To get the list of all keys in a dictionary, use the `list()` built-in function.
5974+
5975+
``` python
5976+
>>> d = {"book": "Python", "year": 1990, "author": "Guido"}
5977+
>>> list(d)
5978+
['book', 'year', 'author']
5979+
```
5980+
5981+
### sorted()
5982+
5983+
To get a sorted list of keys, you can use the `sorted()` built-in function.
5984+
5985+
``` python
5986+
>>> d = {"book": "Python", "year": 1990, "author": "Guido"}
5987+
>>> sorted(d)
5988+
['author', 'book', 'year']
5989+
```
5990+
59715991
## Creating a Copy of a Dictionary
59725992

59735993
A new copy of a dictionary can be made using `copy()` method:

0 commit comments

Comments
 (0)