Commit 8d0ea30
File tree
1 file changed
+1
-1
lines changed- Basics/Exercise/22_list_set_dict_comprehension
- 22_list_set_dict_comprehension.mdhas 1 comment
1 file changed
+1
-1
lines changedOriginal file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1 |
| - | |
| 1 | + | |
2 | 2 |
| |
3 | 3 |
| |
4 | 4 |
| |
|
1 commit comments
Hamdi57 commentedon Mar 30, 2023
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.