سؤال

Would python have a problem dealing with my re-use of item in various for-in loops???

list1 = (A,B,C,D)
list2 = (E,F,G,H)

for item in list1:
    (eg) ...item+5
    (eg) ...item*1

for item in list2:
    (eg) ...item+2
    (eg) ...item*3
هل كانت مفيدة؟

المحلول

Python does not have a problem with re-using names in for loops.

item will get rebound for each and every iteration, you can safely reuse it.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top