“For” loop first iteration

前端 未结 13 2356
渐次进展
渐次进展 2020-12-04 15:17

I would like to inquire if there is an elegant pythonic way of executing some function on the first loop iteration. The only possibility I can think of is:

f         


        
13条回答
  •  伪装坚强ぢ
    2020-12-04 15:44

    Here is what works for me

        dup_count = 0
        for x in reversed(dup_list):
            dup_count += 1
            if dup_count == 1:
                print("First obj {}: {}".format(dup_count,x))
            else:
                print("Object # {}:  {}".format( dup_count,x  ))
    

提交回复
热议问题