OzgeeKorkmaz
Üye
- Mesajlar
- 2
Merhaba arkadaşlar, Pyhton da ingilizce iki sorum var bilenler yazabilirse sevinirim.
soru 1:
Write a function that takes 2 dictionaries as arguments and merges them into a new dictionaryand returns this new dictionary.
If the same key exists in both dictionaries, then the values from each dictionary is combined as a tuple and stored as the value of the key in thenew dictionary. The value from the first dictionary comes first in the tuple.
def mergeDicts(dict1, dict2):
Soru2:
A dictionary is given to you where the value corresponding to each key is the key to another value. For example:
dict = {1:2, 2:3, 3:4, 4:5, 5:-1}
In dict, the value of key 1 is 2, which is the key in 2:3.
Key 2, has value 3, which is the keyin 3:4.
One of the keys has value -1, that is the last key in the chain and it doesn't really point to another key-valuepair. So in the above example key 5 is the last item and it doesnot point to another key-value pair.
Given such a dictionary, write a function that finds the first item in the chain. The function mustreturn the (key,value) tuple for the first key in the chain. For the above example, your function must return (1,2),
because no other key has value 1.
def firstKey(dict):
soru 1:
Write a function that takes 2 dictionaries as arguments and merges them into a new dictionaryand returns this new dictionary.
If the same key exists in both dictionaries, then the values from each dictionary is combined as a tuple and stored as the value of the key in thenew dictionary. The value from the first dictionary comes first in the tuple.
def mergeDicts(dict1, dict2):
Soru2:
A dictionary is given to you where the value corresponding to each key is the key to another value. For example:
dict = {1:2, 2:3, 3:4, 4:5, 5:-1}
In dict, the value of key 1 is 2, which is the key in 2:3.
Key 2, has value 3, which is the keyin 3:4.
One of the keys has value -1, that is the last key in the chain and it doesn't really point to another key-valuepair. So in the above example key 5 is the last item and it doesnot point to another key-value pair.
Given such a dictionary, write a function that finds the first item in the chain. The function mustreturn the (key,value) tuple for the first key in the chain. For the above example, your function must return (1,2),
because no other key has value 1.
def firstKey(dict):