Lists Practice Problem 7

Screen Link:
https://app.dataquest.io/m/1018/lists/7/reversing-and-skipping

My Code:

def best_friday(list_name):
    return list_name[3::7]

What I expected to happen:
Expected the answer to be correct

What actually happened:

Function best_friday did not return the expected value.

Is list_of_customers defined at all?
The hint does not make sense:

print(["a", "i", "u", "e", "o"][4::-2])
['o', 'u', 'a']

4::-2 -> start at 4 and skip 2 till the end

Hey.

It should be start at index 4 and skip 2 until the beginning (it’s going in the opposite direction).

Your solution has two mistakes: wrong start and wrong direction.

Note the following about the input.

The list contains the best customer for each day of the year of 2019 and it is ordered from the first day of the year to the last.

In the instructions it reads:

ordered from the last Friday of 2019 to the the first one.

I hope this helps.

1 Like

Excellent, thank you!

1 Like

Hi Bruno,
Why doesn’t :
return list_of_customers[4:-4:7]
work?

I’m starting on Friday (4) and ending on (-4) which is a saturday but doesnt include saturday as it has a minus sign.
And i’m skipping 7 days.

Thanks

Hey.

The first day isn’t located at index 4.

Both the first and last days of 2019 were a Tuesday.

This means that index 0 is Tuesday. Consequently:

  • 0 is Tuesday
  • 1 is Wednesday
  • 2 is Thursday
  • 3 is Friday

You’re also supposed to reverse the order:

Create a function, best_friday , that takes list_of_customers as input and returns the best customers on each Friday, ordered from the last Friday of 2019 to the the first one.

So your solution, in a sense, is incorrect in two different ways.

2 Likes

A post was split to a new topic: What does “customer” mean in this problem?

Hi Bruno

I’m struggling with understanding the number.

The answer says [-5::-7]. But if Tuesday is set as 0, Friday to the last seems to be -4.

(Monday : -1 Sunday: -2 Saturday: -3)

Could you please answer to that?

Hello,

The first (01/01/19) and last day (12/31/19) of the year are both Tuesday so the elements at index 0 and -1 are Tuesday. I also got confused because I completely forgot Tuesday was also the last day.

1 Like