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 trial
Kabir Gandhiok
12,553 PointsDid not understand why position is decremented by 1
position is decremented by 1 in
shopping_list.insert(position-1, item)
I understand that using insert we have to point to a specific index, but I dont understand why position is decremented by 1, and what will happen if we dont decrement it.
Thanks!
1 Answer
Jesus Mendoza
23,289 PointsHey Kabir,
I haven't seen any Python video but I guess it's because arrays start from the index 0, so let's say position has the value of 1 and you want to point to the element of an array in the first position, you have to pass position-1
Alexander Davison
65,469 PointsAlexander Davison
65,469 PointsThat's actually correct :)
Kabir Gandhiok
12,553 PointsKabir Gandhiok
12,553 PointsThanks! I get it now! :)
Alexander Davison
65,469 PointsAlexander Davison
65,469 PointsPlease give Jesus Mendoza a "Best Answer".
It gives the user who receives it (in this case Mendoza) +12 forum points for that topic of your question (in this case Python).
It also places an extra "Green Check Mark" next to the question in the community which is like saying "This question is answered" so other students can see this is answered right off the bat.
Thank you for understanding. ~Alex