![]() |
|
[Python] How to count the number of items between 2 list items - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [Python] How to count the number of items between 2 list items (/showthread.php?tid=4978107) |
How to count the number of items between 2 list items - Dyst0pia - Sep 6, 2015 Hi guys, I have a list with 6 items in it. I need to output how many items there are between 2 of the list items the users asks for. How can I do this? So for example this is my code: Code bus_stops= ['New York', 'Los Angeles', 'New Jersey ', 'Boston', 'Miami', 'Mexico']I need to calculate how many bus stops there are between the user submitted start and end stations in the bus_stop list. I've read that this is possible with the numPY library but I have't found a way to do it yet. * - cobaltscraper - Sep 6, 2015 Code bus_stops= ['New York', 'Los Angeles', 'New Jersey', 'Boston', 'Miami', 'Mexico']* - c x y k - Sep 6, 2015 Loop until you have position of x, same with y. y - x = d Pretty self explanatory. * - Dyst0pia - Sep 6, 2015 (Sep 6, 2015 02:09 PM)cobaltscraper Wrote: Thank you! that worked perfectly, I completely forgot about looping 😖 * - SIM-1866423 - Sep 6, 2015 PHP Code :) * - Introvert - Sep 7, 2015 Umm... There is no need for a loop here. PHP Code * - Dyst0pia - Sep 8, 2015 (Sep 7, 2015 09:46 AM)Introvert Wrote: Umm... There is no need for a loop here. Thanks for this, it does make it simpler. 🤝 |