i don't use
i also do a lot of deeper system stuff and embedded stuff. but i don't need C for that (or at least not for most of it ... i do for my set-top-box boot loaders) anymore.
why not
range(len(sequence))
to iterate that sequence. i think i recall one use of range(len(sequence))
and it was to make an iterator to recreate a similar sequence in a function (it was py2 and i used xrange). that code would be very different if i re-did it today. all my code would evolve if i re-did everything every day. but i don't have enough time for that. i will re-do a lot of my code, eventually, as i have resolved the last issue preventing me from doing everything in py3 (finally got botocore working correctly in py3 ... a lot of my code uses boto or botocore).i also do a lot of deeper system stuff and embedded stuff. but i don't need C for that (or at least not for most of it ... i do for my set-top-box boot loaders) anymore.
(Mar-20-2017, 11:28 AM)snippsat Wrote: The unwritten rule is simple,never use range(len(sequence)).
If need index or manipulate index alwaysenumerate()
Eg:
# Find index of Lemon in list lst = ['Apple', 'Lemon', 'Orange'] for index, item in enumerate(lst): if item == 'Lemon': print(f'Lemon is at index: {index}')
Output:Lemon is at index: 1
why not
index=lst.index('Lemon')
instead of a loop?
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.