Challenge 5 Megathread

For any and all questions relating to Challenge 5 :point_down: post away!

Will Dot have a meltdown if they have to wait for 15 mins?

6 Likes

So this is a well worded question.
I think if use your knowledge about how to
“loop through key, value of a dictionary” you’ll be fine.

Apologies if I have typos, I need to fall asleep.

3 Likes

Me too, good night :last_quarter_moon_with_face:

1 Like

@Here2Win , thanks for always dropping insight on the challenges. Great job.

Feel free to ask questions everyone.

1 Like

think about how to use .items() to return (key,value) pairs as a tuple from a dictionary.

Can we use a double iteration in a loop?

@VictorLeon you can use two loops. An outer loop and an inner loop. We call this nested loop. Example is;

 # outer for loop
for element in sequence 
   # inner for loop
   for element in sequence:
       body of inner for loop
   body of outer for loop

one of my friends is like this. Hates waiting.

1 Like

It’s confusing, because the second paragraph says

If they waited in line for more than 15 minutes, they might have an emotional meltdown

But the instruction before the definition of the landmarks dictionary says:

develop a list of the landmarks where the wait time is less than 15 minutes

This second instruction is what we need to follow: find landmarks with a wait time strictly less than 15 minutes; a wait time of exactly 15 minutes is too long.

1 Like

You can, but there is a way to avoid this with dictionaries in python. Think about the key and value pair (or look it up of course xD)

not sure if anyone has learned list comprehension yet but a little bit of advice might help you along the way as well as maybe learning something new

the form:

[ i for i in list ]

will generate a list of i items from the inside list

might sound unusual to make a list from a list but the inside list can be any types of iterators, eg dicts, tuples, etc.

however you can also add conditionals inside that list comprehension:

consider

list = [0,3,5,0,3,0,9]
[ i for i in list if i != 0 ] # output [3,5,3,9]

this line will generate a new list made of values in list if i != 0

so this challenge can be a one-liner, at best(you should also learn the different utility methods/functions different data types have, like items() for dicts, etc.)

Caveat, as always: never trust a random guy on the internet and always do extra research. Happy learning

4 Likes

I think it’s well documented in the comparison examples what they want to say.

1 Like

Hi all,

I am completely stuck on this question.
My first solution was just to print the keys and values but I didn’t realize they need to be in a list to get the proper length.
Now, my code looks something like this:

for k,v in landmarks.items():
if v<15:
list=[k]
print(list)

but that just gives me many individual lists. I am not sure how to create only one list. I have been googling but somehow didn’t find what I was looking for.

P.S. I am not enrolled in a BootCamp, I am just taking this opportunity to practice while I am learning python basics on the side. That’s how big newbie I am.

From my end, it looks like the numbers in the dictionary aren’t considered integers which would make it impossible to use in a “if” loop with the condition of being under 15.
I’ve been stuck on this since last night…
So curious how to solve this issue.

A hint I can give you is to avoid using the word ‘list’ to store a variable. that is one of the reserved words in Python Programming language.

You could also start by declaring an empty list, and then use the append() method to fill it up.

Thanks, I managed to figure it out. Turned out to be 2 line code so I am happy about it. Will have to read more about lists and dictionaries.

1 Like

I managed to get it to output the list without much difficulty (though it took me three lines, so I’m curious about the two-line solution). However, once I get it to output the list of landmarks with <15 minute wait times, I don’t know how to get it to also give me the length of that list as a number. Nothing I try with the len() command seems to work, possibly because I don’t know how to tell it to reference the newly generated output. Any thoughts?

Guys, i think that found mistake with correct answer. Means listed answer as “correct” is false.

Can i report it to admin or someone? Cause i don`t want spoil it by screenshots here.