79355811

Date: 2025-01-14 17:17:36
Score: 1
Natty:
Report link

You can visualize what data is shared between variables using package memory_graph

import memory_graph # see install instruction at link above

voting_records = [['1.', 'DIRECTOR', 'Management'],
 ['1', 'Allison Grant Williams', 'For'],
 ['2', 'Sheila Hartnett-Devlin', 'For'],
 ['3', 'James Jessee', 'For'],
 ['4', 'Teresa Polley', 'For'],
 ['5', 'Ashley T. Rabun', 'For'],
 ['6', 'James E. Ross', 'For'],
 ['7', 'Rory Tobin', 'For']]

cnames = ["Record","Proposal","Sponsor","VoteCast"]
voting_records_short = [record for record in voting_records if len(record) < len(cnames)]

if len(voting_records_short) == 0: pass
else:
    ifdirector = ["DIRECTOR" in record for record in voting_records_short]
    if True in ifdirector:
        directorindx = int(ifdirector.index(True))
        directorline = [voting_records_short[directorindx]]
        directors = voting_records_short[directorindx+1:]
        sponsoridx = cnames.index("Sponsor")
        for ls in range(len(directors)):
            directors[ls][0] = directorline[0][0] + directors[ls][0]
            directors[ls][1] = directorline[0][1] + " " +directors[ls][1]
            directors[ls].insert(sponsoridx,directorline[0][-1])

memory_graph.show(locals()) # show a graph of all local variables

which results in:

enter image description here

in which it is clear 'voting_records', 'voting_records_short', and 'directors' share all underlying data. As suggested consider making a deepcopy.

Reasons:
  • Probably link only (1):
  • Contains signature (1):
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: bterwijn