Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics (2015) Python Data Types List cleanup

Carole Cox
Carole Cox
429 Points

"Type" error? In Python basics...

I am getting the following error. I think my logic is correct but I am doing something evil that insults Python.

TypeError: 'type' object is not subscriptable

Here is my code for my code challenge to delete the number 8.

messy = (5, 2, 8, 1, 3) messy_list = list[5, 2, 8, 1, 3] del messy_list[8]

I have tried putting things in and out of quotes. brackets vs paren..

I would greatly appreciate any help and guidance.

lists.py
messy = (5, 2, 8, 1, 3)
messy_list = list[5, 2, 8, 1, 3]
del messy_list[8]
Carole Cox
Carole Cox
429 Points

I really, really want to learn Python. However, I am getting discouraged. it seems like I am getting the logic but I am having more and more trouble getting through the challenges.

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

First, you're doing some extra work. There's no need to make the messy_list. Always a good idea to try not to introduce new variables that they don't ask for in the challenge as it can cause the challenge to fail. Secondly, del removes an item at an index. You're trying to tell it to delete the item at index 8. But there's no item at index 8. The integer 8 is at index 2. Take a look at what you need:

messy = [5, 2, 8, 1, 3]
del messy[2]
Carole Cox
Carole Cox
429 Points

Thank you Jennifer! I hate asking questions because it looks like I don't want to do the work but...you are correct, I have so far, been making things harder. When I get to the workable solution it is fairly simply. I think I get tricked into tying the lecture into the challenge. I really do see what you are saying about the placeholder 2 and had tried that but because I got screwed up with errors, I couldn't see it working.

Phew! I hope I can get past all this. Thank you SOOOO much for your time! Any suggestion as to what resources I can use or tricks I can use to approach these challenges ? I hate bugging you good folks!

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hey Carole Cox sorry for the delay in getting back to you. Really as far as resources, I tend to find that Treehouse itself has the best way of explaining things. You can also do a bit of Googling and sometimes get your answer.

Now for tips and tricks!
Stop. Think. Breathe. Simplify.

The best way to complete any challenge is to read the instructions. I know that sounds simple, but when you start to get frustrated it's generally then that you start to overthink things. Most of the time when I get stuck on a challenge, I go back and re-read the instructions word for word. Did they tell me to name my variable "value" or "values"? Because going into the challenge I have an idea in my head as to what they want me to do. But later when I go back and re-read it.... it generally turns out that what I think they want and what they actually ask for are two separate things.

Try not to introduce new variables into your code that they don't ask for. Pay particular attention to the way they want you to present your results. Did they ask you to print the result or return the result. I've seen many people fail challenges with perfectly functional code simply because they printed instead of returned or vice versa.

If they ask for a string as a result and it's a particular one for example: "Hi there, Carole!". Make sure that's what it actually says. In most cases, the addition of an extra space or the omission of a punctuation mark will cause the challenge to fail. This also goes for capitalization.

Chances are that if you have the suspicion that you're making it too complicated... you are.

Hope this helps, and hang in there! You've got this!

Carole Cox
Carole Cox
429 Points

Jennifer,

Thank you so much for your time, encouragement and effort! Yes, I truly think I am getting what Kenneth says BUT I do have trouble with the challenge questions- more the questions than the answers! I will keep plugging along and hope that no one minds me asking for another eye on things when I get hung up. I want this!

I hope you have a great day.