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
  problem in using generator akbarza 2 504 Nov-07-2023, 08:40 AM
Last Post: perfringo
  for loops break when I call the list I'm looping through Radical 4 880 Sep-18-2023, 07:52 AM
Last Post: buran
  with open context inside of a recursive function billykid999 1 570 May-23-2023, 02:37 AM
Last Post: deanhystad
  How do I call sys.argv list inside a function, from the CLI? billykid999 3 787 May-02-2023, 08:40 AM
Last Post: Gribouillis
  Problem with "Number List" problem on HackerRank Pnerd 5 2,083 Apr-12-2022, 12:25 AM
Last Post: Pnerd
  List Iteration Help javeeva 2 1,182 Feb-07-2022, 11:23 PM
Last Post: snippsat
  asyncio calls within sync function ( Websocket on_open) orion67 0 1,398 Jan-16-2022, 11:00 AM
Last Post: orion67
  Problem With Database Calls and Load Timbo03 1 2,118 Nov-21-2021, 10:48 AM
Last Post: Timbo03
  Tuple generator, and function/class syntax quazirfan 3 3,854 Aug-10-2021, 09:32 AM
Last Post: buran
  Why recursive function consumes more of processing time than loops? M83Linux 9 4,210 May-20-2021, 01:52 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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