-1

I have created database of different payments in different departments:

paymentType={"Cash":0,"Amex":0,"All Other Cards":0}
departments={"Lounge":0,"MBar":0,"Resto":0,"TBar":0,"TFloor":0,"Events":0}
for dep in departments.keys():
    data=paymentType
    departments[dep]=data

however, when I assign value to one of “paymentType” in specific department

departments["Lounge"]["Cash"]=8

it changes “Cash” value in all “departments”

I would like to keep ability to assign value by string, thats why I didnt use class.

Matus Hmelar
  • 348
  • 3
  • 13

1 Answers1

1

You need to use

data=paymentType.copy()

otherwise you assign the same dictionary to all fields.

Tammo Heeren
  • 1,966
  • 3
  • 15
  • 20