If list index exists, do X

前端 未结 12 834
清酒与你
清酒与你 2020-12-02 11:41

In my program, user inputs number n, and then inputs n number of strings, which get stored in a list.

I need to code such that if a certain

12条回答
  •  -上瘾入骨i
    2020-12-02 12:20

    You can try something like this

    list = ["a", "b", "C", "d", "e", "f", "r"]
    
    for i in range(0, len(list), 2):
        print list[i]
        if len(list) % 2 == 1 and  i == len(list)-1:
            break
        print list[i+1];
    

提交回复
热议问题