Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAdiv Abramson
6,919 PointsIs it overkill to put the call to .append() a new item to shopping_list in a try/except block?
In my version I test the input to see if it exists in the shopping_list already. If it does then I reject the input.
I also put the call to .append() a new item within a try/except block. Is that overkill? I mean, are there conditions in which .append() can fail? I understand that if the list in question is actually a set (which consists of unique values only) then .append() could raise an error. But with a regular list is it possible to add something to it that crashes the program?
1 Answer
mkmk
15,897 PointsIt does seem a bit overkill; if you have already tested for an acceptable input, I don't see how a passed input would crash append(). I did a quick web search on it and could not find anything that would suggest otherwise.