How to rewrite this Dictionary For Loop in Python? -
I have a dictionary of classes where classes contain attributes of string lists.
I created this function to find maximum things in one of those lists for a particular person I made.
def find_max_var_amt (some_person) #pass In a patient ID number, retrieve their maximum number variable for a variables of variables = max_vars = 0, value in patients [some_person] .__ dict __ Item (): challenger = len (value) if max_vars & lt; Challenge: Maximum_WARS = Challenger returns max_vars
What I have to do, is to write it again so that I do not use the .iteritems () function. This find_max_var_amt
function works well, but I am converting my code using a database using DBM module, so the typical dictionary function now assigns syntax to work for me Despite not doing it and reaching the key: the value pairs will be similar thanks for your help!
Since DBM
does not require you to run the value directly, you have keys To do this, you can modify < for
loop
for the key in patients [some_person] .__ dict__: value I think a big issue, however, will be the fact that dbm / Code> stores only stars, then you Will not be able to store the list directly in the database; You have to represent this string. And this means that when you try to calculate the length of the list, it will not be as simple as len (; You have to develop some code that will detect the length of the list based on the string that you use. It can be as simple as lane (the_string.split (','))
, just know that you have to do this.
By the way, your existing function, the use of a generator can be rewritten so that:
def find_max_var_amt (some_person): (patients [some_person] .__ The value in the dict (values) itervalues for value __ ()) return max
and if you did it like this, the changes to replicate on the keys
Look for> DIF = DAC (DCT [Key])
Pre>
Comments
Post a Comment