Helicopter Prison Break Project, 7th screen - not getting the list without its last element

Hello everyone, my name is Harneet and I am new to coding and whole CS world. I have taken this course from data quest to improve my skills in python and SQL, however I’m having issues in going through the project.
The code given for 7th screen is not working and I am not getting the desired list without its last element. Did anyone faced similar issue? I want to complete this project as I am struck on this from a long time. So, it will be really grateful if any of you could help.
Thanks.

1 Like

Hi @oblivionneet,

Welcome to the community!

Can you share your code that is not working?

Hey @Casandra_Hayward,
I believe I’m facing the same problem (the 7th screen), and I’ve hence attached my code for your perusal

index = 0
for row in data[:3]:
data[index] = row[:-1]
index += 1

print(data[:3])

Hi @navyakukreja9

Welcome to the community.

What was your error message?

You can remove the [:3] from for row in data[:3]
so the for loop will go through the entire data set like the Updated Code below.

Otherwise, if you add data[:3], you will only loop through the first 3 rows. Here is more information about slicing a list.

Updated Code :

index = 0
for row in data:  # loop through the entire data set
   data[index] = row[:-1]
   index += 1

print(data[:3])
1 Like

@Casandra_Hayward
Thank you for your speedy response!
There was no error message, however, the code that should have worked (to the best of my knowledge) did not work.
I was expecting an output without the final element in the list of lists, but for some reason, it just wouldn’t do that.
Anyway, the same code does work now, which is a little uncanny, but thanks for your help!

1 Like