0

I created a simultaneous loop by referring to this StackOverflow-page, like this:

s = '0123456789'         
index = 5
  
for i, j in zip(range(index-1,-1,-1), range(index+1,len(s))):
    print (s[i], s[j])

For the above code I get the following output:

4 6
3 7
2 8
1 9

But I need to break a loop if it's out of index and still continue the other loop, so for the above example I would like to get an output something like this:

4 6
3 7
2 8
1 9
0 None

And if I consider index as 3 I would like to get the output something like this:

2 4
1 5
0 6
None 7
None 8
None 9

Or if I consider index as 7 I would like to get the output something like this:

6 8
5 9
4 None
3 None
2 None
1 None
0 None
Johan Jomy
  • 592
  • 2
  • 7
  • 22

0 Answers0