Hi I want my output to be
add_sizes(['hello', 'world']) -> [('hello', 5), ('world', 5)]
but I'm getting
add_sizes(['hello', 'world']) -> [('hello', 5), ('hello', 5, 'helloworld', 5)]
My code is
def add_sizes(strings):
s = ()
t=[]
m=[]
for i in strings:
x=i
for i,c in enumerate(list(x)):
t.append(c)
l=(str(''.join(t)),i+1)
s += l
m.append(s)
print(m)
Any suggestion would be appreciated thanks
stringsalong with thelen()of the string. Append these, one by one, to a list and return/print the list when you're done. Yourenumerateandl=(str(''.join(t)),i+1)statements aren't necessarys=();t=[](should be inside the loop) but as eugene y says, the better solution is a list comprehension.