Sep-30-2022, 10:38 PM
i am iterating over a list (or tuple). for each item except the last item i need to do a specific thing. for the last item i need to do something different. the solution i am thinking about is to get the initial len() of the list and count as the iterating proceeds. if the counting is up, i detect the last when the count equals the length. another way is iterating over range(len(seq)-1) and indexing the sequence like:
there are many ways to do this. which would be the best? which would be most pythonic?
1 2 3 |
for x in range ( len (seq) - 1 ): foo(seq[x]) bar(seq[ - 1 ]) |
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.