Write a one-liner approach for this output in python.
Attachments:
Answers
Answered by
19
Solution:
Using one-liner approach, the códe goes like -
print(*["\n"+(str(i)+" ")*(i+1) for i in range(5)]*5)
Logic:
STEP 1: Create a list that stores the given string -
0
1 1
2 2 2
3 3 3 3
4 4 4 4 4
STEP 2: Unpacking the list and multiplying the list by 5 so as to display it 5 times.
Refer to the attachment for output.
•••♪
Attachments:
Answered by
1
Answer:
file = open ( 'gfg.txt' , 'r' ) lis = [] for each in file : # removing '\n' from the end of the string. a = each[: - 1 ] lis.append(a) file .close()
lis = [line.strip() for line in open ( 'gfg.txt' , 'r' )]
My Personal Notes arrow_drop_up.
Similar questions