Challenge 3 Megathread

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

I think this question was decently worded and made sense.

For anyone wondering what negative numbers do in a list, try it out.Try printing the output and you’ll be surprised. Just drop a print() around whatever you’re slicing and you should see an output.
a_list[-1] gets the last index
a_list[-2], gets the second last index

and so on.
It’s the equivalent of a_list[len(a_list)-1] and a_list[len(a_list)-2]. Can you see a pattern?

You can also slice with negative numbers.
list[-3:] will give you the last 3 elements in a list.
a_list[-3:-2], will only give you the 3rd last element.

Also keep in mind that the answer wants you to use PYTHON indexing, aka start counting from 0.
Row 1 = 0
Row 2 = 1

and so on.

The same follows for inside the list.
a_list[0][0] will return the element in the top left
a_list[-1][-1] will return the element in the bottom right.

11 Likes

Hello everyone!!

I’m here to moderate the forum for the next 2 hours. If you have any questions, kindly ask. You can also discuss amongst yourselves without sharing answers.

Kelvin.

@Here2Win thanks for your explanation on python list indexing.

What is the variable name of the nested list that we can work with? I tried printing layout[0] or new_layout[0] but it says they are not defined or do I just make it myself? That’s not how it normally goes, so just want to confirm

@hfxtom I think layout should work. However, you should define it within the code cell and run it. That way, the nested list will be assigned to a variable name.

Thanks. Normally the variables are established and we can work with them right away. I wasn’t expecting to have to declare it myself first - all good!

1 Like

Found today’s challenge very confusing…
Next sit…is that the one before/after/by
Very confusing and could go different ways in everybody’s mind.

frustrated

3 Likes

What’s confusing exactly @elasticman?

Have you gone through the link attached?

The exercise says list_of_int[0:2] will print 3 elements, but it is wrong, it will print two.

5 Likes

That was a mistake. Of course, 0:2 will print the first two element from the list. Thanks for the feedback.

1 Like

Not sure which link you are referring to but I meant about the purpose of the exercise
.
The wording around the “The next seat needs to be empty”

@elasticman, figuring this is part of the challenge.

Think about it like this;

I need a seat, but the sit must be;

  1. empty
  2. close to an empty seat
  3. must be a seat next to the window.

Go through the nested array and see which element(s) actually meets this condition. Then using multiple-level indexing, get the seat.

I hope this clue helps.

@samson_samul, there are majorly two ways to index an array;

  • positive indexing
  • negative indexing.

Stick to one convention.

Another part of the question/instructions that I found confusing was when you display the answers to choose from, are those meant to be the seat and row numbers, or the index number?

My guess is that it’s meant to be the seat and row numbers, but it’s confusing because you use a [-x] notation which makes it seam it’s an index - which would then change the answer someone would pick due to the whole indexes starting with 0 thing.

2 Likes

Make sure you’re running the cells that define those variables, I had an issue with this particular workbook where layout variable wasn’t being defined in the cell it was written - so I moved those contents into a new cell and then it ran just fine.

1 Like

Hi @Kelvine95! I submitted the correct answer but it was marked incorrect, is there a way to request a fix of this?

Kindly share your email with me and username, we can check on our end. Thank you

Kindly share your email with me and username, we can check on our end. Thank you

Yeah that is what I understood but then I thought [5][-1] would work…

2 Likes