Python Forum
list call problem in generator function using iteration and recursive calls - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: list call problem in generator function using iteration and recursive calls (/thread-30530.html)



list call problem in generator function using iteration and recursive calls - postta - Oct-24-2020

[inline]I want to convert any long integer number from 12576 to [6, 2], all the following snippets give me [[6, 2]] I want to remove the 2nd square bracket

gen = evens(1234)
print(next(gen)) # gives ==> [4, 2]


but


list(evens(1234) # gives ==> [[4, 2]]



is there is another method to eliminate the second square brackets using the same generators
thanks in advance[/inline]


RE: list call problem in generator function using iteration and recursive calls - bowlofred - Oct-24-2020

I'm not sure what you're asking. It looks like asking for an element of your generator (can you post the generator code?) already gives you exactly what you want. If you put it in a list, it adds another layer of list (a second set of brackets).

So don't put it in the list and you should be good.

Can you give more information why print(next(gen)) # gives ==> [4, 2] isn't sufficient?