0

Add elements in tuple

The first line contains (a total number of elements initially) and in next n line containing space separated tuple elements. In last line have index value and element followed by space

18th Nov 2020, 8:55 AM
Ajith
Ajith - avatar
4 Respostas
+ 2
l = [] for _ in range(int(input())): l.append(input()) # out of loop index, value = input().split() l.insert(int(index), value) t = tuple(l) print(t)
18th Nov 2020, 9:18 AM
ChaoticDawg
ChaoticDawg - avatar
0
Sample inputs 5 abda cgsl 123 held Hold 3 three ## it needs to insert three at index value 3 Sample output#it should be in tuple ('abda','cgsl',123,'three','Held','Hold')
18th Nov 2020, 8:58 AM
Ajith
Ajith - avatar
0
n=input() list=[] for i in range(0,n): list.append(input()) last_line=input() spl=last_line.split() pos=int(spl[0]) ele=spl[1] list.insert(pos,ele) print(tuple(list))
18th Nov 2020, 9:03 AM
Ajith
Ajith - avatar
0
Understood thanks
18th Nov 2020, 1:00 PM
Ajith
Ajith - avatar