From 2752111ddfeed3f6556a7405c6ede0827296cb48 Mon Sep 17 00:00:00 2001 From: Ankit Mahato Date: Wed, 29 Mar 2023 06:52:13 +0530 Subject: [PATCH] Builtin functions list & sorted on dict --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.md b/README.md index d357fb3..b38ebc7 100644 --- a/README.md +++ b/README.md @@ -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: