Akrep Kral

Greenhorn
+ Follow
since May 10, 2020
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Akrep Kral

Junilu Lacar wrote:

Akrep Kral wrote:when we print this" print(firstKey({3:4, 5:-1, 1:2, 2:3, 4:5})) " , the answer needs to come to (5, -1) ?


No. That would be the exact opposite of what is being asked.



where is the bug ???


3 years ago

Junilu Lacar wrote:Study this part of the question very carefully: "The function must return 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."

It gives you an idea of what you're looking for in order to determine which is the first key in the chain.




when we print this" print(firstKey({3:4, 5:-1, 1:2, 2:3, 4:5})) " , the answer needs to come to (5, -1) ?
3 years ago

Campbell Ritchie wrote:Please show us what you tried, even if it was unsuccessful.




def firstKey(dict):
   for k,v in dict.items():
       if v == -1:
           a = k
   while True:

i can come hear
3 years ago
I tried very hard but I couldn't do these 2 questions
3 years ago
"""
Question 3

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 key in 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-value pair. So in the above example
key 5 is the last item and it does not point to another key-value
pair.

Given such a dictionary, write a function that finds the first
item in the chain. The function must return 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):





"""
Question 4

A dictionary is given to you as described in Question 3.
Write a function that converts this dictionary to a list,
such that for every pair of consecutive items in the list,
there is a corresponding key-value pair in the dictionary.
For example, given the following dictionary:
{5:1, 2:5, 1:3, 7:-1, 3:7}
your function must return:
[2, 5, 1, 3, 7]
So, 2:5, 5:1, 1:3, 3:7 and 7:-1 are key-value pairs in
the dictionary.
"""

def dictToList(dict):
3 years ago