0

Is there a simple way to pull list indices from a dictionary value?

Central_Bonds_Cyclo = { 'A1-A2' : [A1,A2], 'A1-A4' : [A1,A4], 'A2-A3' : [A2,A3], 'A3-A4' : [A3,A4] }

Suppose I want to pass each two member list into a function:

CycloButadiene += LineSegment( A1, A2, 1, color = 'white' )
CycloButadiene += LineSegment( A1, A4, 1, color = 'white' )
CycloButadiene += LineSegment( A2, A3, 1, color = 'white' )

This is currently how I'm going about it:

def bond_split(AxAy):
    x = AxAy[0]
    y = AxAy[1]
    return(x,y)
for bond in Central_Bonds_Cyclo:
        Benzene += LineSegment(bond_split(Central_Bonds_Cyclo[bond])[0],
        bond_split(Central_Bonds_Cyclo[bond])[1], 1, color = 'white' )

Is there a more elegant method to approach this?

carcinogenic
  • 169
  • 1
  • 2
  • 10

1 Answers1

1

You can use argument unpacking via * syntax:

for key, value in Central_Bonds_Cyclo.items():
    Benzene += LineSegment(*value, 1, color='white')
a_guest
  • 34,165
  • 12
  • 64
  • 118