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 / 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 By the way, your existing function, the use of a generator can be rewritten so that: and if you did it like this, the changes to replicate on the keys DBM
does not require you to run the value directly, you have keys To do this, you can modify < for
Pre> loop
for the key in patients [some_person] .__ dict__: value I think a big issue, however, will be the fact that
dbm
len (
lane (the_string.split (','))
, just know that you have to do this.
def find_max_var_amt (some_person): (patients [some_person] .__ The value in the dict (values) itervalues for value __ ()) return max
Comments
Post a Comment