Skip to content

Commit 8d0ea30

Browse files
author
Karandeep Grover
committedFeb 15, 2021
Merge branch 'master' of github.com:codebasics/py
2 parents ecfb51a + e2adec3 commit 8d0ea30

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed
 

‎Basics/Exercise/22_list_set_dict_comprehension/22_list_set_dict_comprehension.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Exercise: Generators
1+
## Exercise: List Set Dict Comprehensions
22

33

44
1. Create a Dictionary which contains the Binary values mapping with numbers found in the below integer and binary and save it in binary_dict.

1 commit comments

Comments
 (1)

Hamdi57 commented on Mar 30, 2023

@Hamdi57

tamsayı = [0, 1, 2, 3, 4]
ikili = ["0", "1", "10", "11", "100"]

binary_dict = {tamsayı[i]: ikili[i] for i in range(len(tamsayı))}
print(binary_dict)

Here the dictionary is matched with the keys of the numbers in the integer list and the values of the numbers in the binary list. The expression range(len(integer)) returns an array of numbers containing the indices of all items in the integer list. The dictionary keys and values are then assigned one by one using the for loop and the expression range(len(integer)), creating the dictionary named binary_dict.

Please sign in to comment.