I am trying to convert the display the content of the list such that only three elements print in each line, and able to write the below code using if/else, which is working as expected..
lst = ["s1","s2","s3","s4","s5","s6","s7","s8"]
cnt=0
var4=""
for i in range(len(lst)):
if (cnt%3) == 0:
var4 = var4 + "\n" + lst[i]
else:
var4 = var4 + ", " + lst[i]
cnt +=1
print(var4)
Output:
s1, s2, s3
s4, s5, s6
s7, s8
Trying to find if the same result can be achieved using List Comprehension or some other efficient possible way.
thanks..!!