Mar-27-2020, 04:01 PM
Read your question out loud to yourself. The answer is there.
I think your problem is you are worrying too much about how to do stuff in python and it is preventing you from seeing how simple this is. I will rephrase your question.
I want to pick up all the rocks. How will I know when to stop picking up rocks?
I use rocks not because I think your head is full of rocks, but because most programming problems are so simple a cavman could do it (reference to old GEICO commercial in the USA). If programming was really hard there wouldn't be millions of people who can program. But new programmers often make the mistake of trying to design code at the keyboard. At the keyboard you need to think about syntax and spelling and punctuation and what commands are available and what arguments the commands take and..... When you become proficient in a language most of that stuff happens subconsciously, but when you are starting it can be overwhelming and make really smart people stupid.
Right now I have two pads of paper and pens and pencils sitting next to me. When I have a problem with the program I am working on it is the pencil and paper I reach for first, not the keyboard. I write my solution using pictures and natural language, not Python or C. When I am happy with the solution I translate it into programming language. Sometimes the translation requires modifications to the solution. but usually not.
Your problem is: If I want to process all the items in a list, how do I know when to stop?
See? Not any harder than picking up rocks.
I think your problem is you are worrying too much about how to do stuff in python and it is preventing you from seeing how simple this is. I will rephrase your question.
I want to pick up all the rocks. How will I know when to stop picking up rocks?
I use rocks not because I think your head is full of rocks, but because most programming problems are so simple a cavman could do it (reference to old GEICO commercial in the USA). If programming was really hard there wouldn't be millions of people who can program. But new programmers often make the mistake of trying to design code at the keyboard. At the keyboard you need to think about syntax and spelling and punctuation and what commands are available and what arguments the commands take and..... When you become proficient in a language most of that stuff happens subconsciously, but when you are starting it can be overwhelming and make really smart people stupid.
Right now I have two pads of paper and pens and pencils sitting next to me. When I have a problem with the program I am working on it is the pencil and paper I reach for first, not the keyboard. I write my solution using pictures and natural language, not Python or C. When I am happy with the solution I translate it into programming language. Sometimes the translation requires modifications to the solution. but usually not.
Your problem is: If I want to process all the items in a list, how do I know when to stop?
See? Not any harder than picking up rocks.