0
Python: .join method
def func(x): for i in range(x): yield i**2 print(",".join(list(func(3)))) # outputs TypeError: sequence item 0: expected str instance, int found The join() method takes all items in an iterable and joins them into one string. So I instead tried converting the func to a string instead: def func(x): for i in range(x): yield i**2 print(",".join(list(str(func(3))))) #outputs <,g,e,n,e,r,a,t,o,r, ,o,b,j,e,c,t, ,f,u,n,c, ,a,t, ,0,x,7,f,f,4,6,a,6,4,f,3,5,0,> Why did this happen? How can I simply get 0,1,4 or [0,1,4] or ["0", "1", "4"] as intended?
2 Respostas
+ 3
yield str(i**2)