Python Forum

Full Version: list call problem in generator function using iteration and recursive calls
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
[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]
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?