Python Forum
generator function that yield from a list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
generator function that yield from a list
#10
Here with re.finditer(),so it's still regex but an alternative way of using regex.
addresses = btInfo.group().split()
for idx in range(len(addresses)):
So here use @r0ng split() and range(len(addresses),together with regex.

import re

foo = "70D76320 BEG 701D135D 702D72FC END EAR0 00000000 0000000"
for match in re.finditer(r'BEG\s(.*?)\s(.*?)\s', foo):
    for idx,address in enumerate(iter(match.groups())):
        print(f'[{idx}]0x{address}')
Output:
[0]0x701D135D [1]0x702D72FC
Reply


Messages In This Thread
RE: generator function that yield from a list - by snippsat - Jun-04-2019, 10:26 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  yield from akbarza 4 413 Apr-19-2024, 07:58 PM
Last Post: DeaD_EyE
  yield usage as statement or expression akbarza 5 916 Oct-23-2023, 11:43 AM
Last Post: Gribouillis
  Using list comprehension with 'yield' in function tester_V 5 1,348 Apr-02-2023, 06:31 PM
Last Post: tester_V
  Tuple generator, and function/class syntax quazirfan 3 3,995 Aug-10-2021, 09:32 AM
Last Post: buran
  What is the difference between a generator and a list comprehension? Pedroski55 2 2,281 Jan-02-2021, 04:24 AM
Last Post: Pedroski55
  Yield generator weird output Vidar567 8 3,356 Nov-23-2020, 10:59 PM
Last Post: deanhystad
  Creating list of lists from generator object t4keheart 1 2,244 Nov-13-2020, 04:59 AM
Last Post: perfringo
  list call problem in generator function using iteration and recursive calls postta 1 1,979 Oct-24-2020, 09:33 PM
Last Post: bowlofred
  Trying to access next element using Generator(yield) in a Class omm 2 2,034 Oct-19-2020, 03:36 PM
Last Post: omm
  Yield statement question DPaul 6 2,571 Sep-26-2020, 05:18 PM
Last Post: DPaul

Forum Jump:

User Panel Messages

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