+ 4

Create simple table with for-loop

i just trying to create simple table with following this code. n = 0 x = ["list1","list2","list3","list4"] for y in x: n+=1 h="{}. {}".format(n,y) + ' ' + "{}. {}".format(n+n,y) print(h) but i didn't output what i want,like this 1. list1 3. list3 2. list2 4. list4

21st Nov 2018, 3:30 PM
Ali
Ali - avatar
1 Answer
+ 13
Try this code. x=['list1','list2','list3','list4'] for i in range(0,len(x),2): print(f'{i}.{x[i]} {i+1}.{x[i+1]}') #this will give you right output as you want.
21st Nov 2018, 4:39 PM
Maninder $ingh
Maninder $ingh - avatar