A question about finditer output in regularization

for index, row in train_set.iterrows ():

S = str(row[""])
M = re.finditer(match_target, S)
part_index_list = [(m.start(), m.start() + len(m.group()) - 1) for m in M]
part_list = [m.group() for m in M]
After

run, the part_index_list list has a normal value, and part_list has been empty all the time. Theoretically, part_index_list should be corresponding to part_list, empty or non-empty at the same time. The result seems to be unscientific.


because the elements in generator M are already consumed when assigning a value to part_index_list, there are no elements in M when assigning a value to part_list.


reason @ pein has been given.
what better way to do than to finditer again? , you can do this:

part_tuple = [((m.start(), m.start() + len(m.group()) - 1), m.group()) for m in M]
part_index_list, part_list = zip(*part_tuple)
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1be5844-30ccc.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1be5844-30ccc.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?