From 5754af805fe15b83c779e801a5bf2ff0332278dd Mon Sep 17 00:00:00 2001 From: mattveraldi Date: Tue, 23 Oct 2018 12:46:20 +0200 Subject: [PATCH 1/3] Solved issue #53 --- snippets/keys_only.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/snippets/keys_only.md b/snippets/keys_only.md index f53a32107..7a566a1fd 100644 --- a/snippets/keys_only.md +++ b/snippets/keys_only.md @@ -2,14 +2,11 @@ Function which accepts a dictionary of key value pairs and returns a new flat list of only the keys. -Uses the .items() function with a for loop on the dictionary to track both the key and value and returns a new list by appending the keys to it. Best used on 1 level-deep key:value pair dictionaries (a flat dictionary) and not nested data-structures which are also commonly used with dictionaries. (a flat dictionary resembles a json and a flat list an array for javascript people). +Uses the .keys() method of "dict" objects. dict.keys() returns a view object that displays a list of all the keys. Then, list(dict.keys()) returns a list that stores all the keys of a dict. ``` python def keys_only(flat_dict): - lst = [] - for k, v in flat_dict.items(): - lst.append(k) - return lst + return list(flat_dict.keys()) ``` ``` python From 74251fe1a59d39bff648f07a84052fb98b2cf523 Mon Sep 17 00:00:00 2001 From: mattveraldi Date: Tue, 23 Oct 2018 12:53:46 +0200 Subject: [PATCH 2/3] Solved issue #53 --- contributor_database | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contributor_database b/contributor_database index 66bbf0288..fb69263e0 100644 --- a/contributor_database +++ b/contributor_database @@ -25,6 +25,6 @@ insertion_sort:[Meet Zaveri](@meetzaveri),[Rohit Tanwar](@kriadmin) difference_by:[Rohit Tanwar](@kriadmin) bubble_sort: [Shobhit Sachan](@sachans) has_duplicates: [Rob-Rychs](@Rob-Rychs) -keys_only: [Rob-Rychs](@Rob-Rychs) +keys_only: [Rob-Rychs](@Rob-Rychs),[Matteo Veraldi](@mattveraldi) values_only: [Rob-Rychs](@Rob-Rychs) all_unique: [Rob-Rychs](@Rob-Rychs) \ No newline at end of file From 1f4aeb531d250afa2521834f2598a4a1ee6b1a6b Mon Sep 17 00:00:00 2001 From: mattveraldi Date: Tue, 23 Oct 2018 13:04:27 +0200 Subject: [PATCH 3/3] Solved issue #53 --- test/keys_only/keys_only.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/keys_only/keys_only.py b/test/keys_only/keys_only.py index 43d879917..ab1f21176 100644 --- a/test/keys_only/keys_only.py +++ b/test/keys_only/keys_only.py @@ -1,5 +1,2 @@ def keys_only(flat_dict): - lst = [] - for k, v in flat_dict.items(): - lst.append(k) - return lst \ No newline at end of file + return list(flat_dict.keys()) \ No newline at end of file