“Pemahaman Kamus Python” Kode Jawaban

Python Set dan Dictionary Comprompleensions

simple_dict = {
    'a': 1,
    'b': 2
}
my_dict = {key: value**2 for key,value in simple_dict.items()}
print(my_dict)
#result = {'a': 1, 'b': 4}
Blue-eyed Bat

Dikt Pemahaman Python

# dict comprehension we use same logic, with a difference of key:value pair
# {key:value for i in list}

fruits = ["apple", "banana", "cherry"]
print({f: len(f) for f in fruits})

#output
{'apple': 5, 'banana': 6, 'cherry': 6}
Handsome Hamster

Pemahaman Dikt Python

>>> {x: x**2 for x in (2, 4, 6)}
{2: 4, 4: 16, 6: 36}
Splendid Serval

Kamus Pemahaman Python

print({i:j for i,j in zip(txt_list,num) if i!="All"})
Grieving Goshawk

pemahaman dikt

# Dictionary comprehension

{i:i*2 for i in range(10)}
alberduris

Pemahaman Kamus Python

# Dictionary Comprehension
squares = {x: x*x for x in range(6)}

print(squares)
SAMER SAEID

Jawaban yang mirip dengan “Pemahaman Kamus Python”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya