I am using Python in colab research. I have this code to count cards and say how many full decks exist on 'A':
A = ["1P", "1C", "1O", "2P", "2C", "2O", "2E", "3P", "3C", "3O", "3E", "4P", "4C", "4O", "4E", "5P", "5C", "5O", "5E",
"6P", "6C", "6O", "6E", "7P", "7C", "7O", "7E", "8P", "8C", "8O", "8E", "9P", "9C", "9O", "9E", "DP", "DC", "DO",
"DE", "10P", "10C", "10O", "10E", "VP", "VC", "VO", "VE", "RP", "RC", "RO", "RE", "1P", "1C", "1O", "1E", "2P", "2C",
"2O", "2E", "3P", "3C", "3O", "3E", "4P", "4C", "4O", "4E", "5P", "5C", "5O", "5E", "6P", "6C", "6O", "6E", "7P",
"7C", "7O", "7E", "8P", "8C", "8O", "8E", "9P", "9C", "9O", "9E", "DP", "DC", "DO", "DE", "10P", "10C", "10O", "10E",
"VP", "VC", "VO", "VE", "RP", "RC", "RO", "RE", "1P", "1C", "1O", "1E", "2P", "2C", "2O", "2E", "3P", "3C", "3O",
"3E", "4P", "4C", "4O", "4E", "5P", "5C", "5O", "5E", "6P", "6C", "6O", "6E", "7P", "7C", "7O", "7E", "8P", "8C",
"8O", "8E", "9P", "9C", "9O", "9E", "DP", "DC", "DO", "DE", "10P", "10C", "10O", "10E", "VP", "VC", "VO", "VE", "RP",
"RC", "RO", "RE"]
B = {'1P': 0, '1E': 0, '1C': 0, '1O': 0, '2P': 0, '2E': 0, '2C': 0, '2O': 0, '3P': 0, '3E': 0, '3C': 0, '3O': 0,
'4P': 0, '4E': 0, '4C': 0, '4O': 0, '5P': 0, '5E': 0, '5C': 0, '5O': 0, '6P': 0, '6E': 0, '6C': 0, '6O': 0,
'7P': 0, '7E': 0, '7C': 0, '7O': 0, '8P': 0, '8E': 0, '8C': 0, '8O': 0, '9P': 0, '9E': 0, '9C': 0, '9O': 0,
'10P': 0, '10E': 0, '10C': 0, '10O': 0, 'DP': 0, 'DE': 0, 'DC': 0, 'DO': 0, 'VP': 0, 'VE': 0, 'VC': 0, 'VO': 0,
'RP': 0, 'RE': 0, 'RC': 0, 'RO': 0}
for i in range(0, len(A)):
B[A[i]] += 1
min = min(B.values())
print(min)
I run the code once and it works, but if I run min = min(B.values())
again, I get an error:
TypeError: 'int' object is not callable
Any ideas on what might be happening?
You should assign the value to a variable other than min
.
When you run min = min(B.values())
you are re-assigning the function min
to a number, so next time you run the code, min
is no longer a function and you can't call it again.
Using a different variable name would solve the problem:
minvalue = min(B.values())
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.