dictionary - Confused about python syntax -
i have looked on web , have not been able find answer question. trying understand python code , came across class declaration looks this:
s_list = [] last_name = "" def __init__(self, last_name, curr_date, difference): self.last_name = last_name self.s_list = {curr_date:difference} self.d_list = [] self.d_list.append(curr_date)
what happening inside curly braces? initializing dictionary? later in main file used this:
n = n_dict[last_name] n.d_list.append(curr_date) n.s_list[curr_date] = difference
where n temporary dictionary used add onto n_dict, n_dict being dictionary contains information class.
why {:} notation used? there other way have been done?
any answers appreciated!
{curr_date:difference}
created anonymous dictionary.instead, can create dictionary name :
dict_name={} dict_name[curr_date]= difference self.s_list=dict_name
also, can create dictionary using dict()
: self.s_list=dict(curr_date=difference)
there other ways create dictionary in python!
Comments
Post a Comment