Python Forum
list call problem in generator function using iteration and recursive calls
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
list call problem in generator function using iteration and recursive calls
#1
[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]
Reply
#2
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?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Combine Two Recursive Functions To Create One┬áRecursive Selection Sort Function Jeremy7 12 509 Jan-17-2021, 03:02 AM
Last Post: Jeremy7
  What is the difference between a generator and a list comprehension? Pedroski55 2 152 Jan-02-2021, 04:24 AM
Last Post: Pedroski55
  In this function y initially has no value, but a call to foo() gives no error. Why? Pedroski55 8 336 Dec-19-2020, 07:30 AM
Last Post: ndc85430
  Execution of Another Recursive Function muzikman 5 272 Dec-04-2020, 08:13 PM
Last Post: snippsat
  Don't Understand Recursive Function muzikman 9 300 Dec-03-2020, 05:10 PM
Last Post: muzikman
  How to create a linked list and call it? loves 12 493 Nov-22-2020, 03:50 PM
Last Post: loves
  Creating list of lists from generator object t4keheart 1 201 Nov-13-2020, 04:59 AM
Last Post: perfringo
  Struggling for the past hour to define function and call it back godlyredwall 2 267 Oct-29-2020, 02:45 PM
Last Post: deanhystad
  function call at defined system time? Holon 5 442 Oct-06-2020, 03:58 PM
Last Post: snippsat
  user input for multi-dimentional list without a prior iteration using input() Parshaw 6 457 Sep-22-2020, 04:46 PM
Last Post: Parshaw

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020