Newbie python programmer here, so i apologise if this question has been asked but i could not find an answer that i understood and could apply to my code.
basically i have a dictionary my_dict
which is of len(x)
, where 4 < x < 100
.
the dictionary is in the form:
{ 0: (bg_colour, text_colour), ..., x: (bg_colour, text_colour)) }
where the values of bg_colour
and text_colour
will be updated as the program runs.
Later in my code i want to call a function to draw rectangles on a canvas based on this dictionary, and I am meant to use the **kwargs
as an argument to make this happen. I have tried using:
func(**mydict)
, but get error: keywords must be strings
.
So my question is how can I transform my_dict
into a form where it is recognisable by **kwargs
?
From what I have read i have to get it into a string form such as:
my_dict = '0=(bg_colour, text_colour), ..., x=(bg_colour, text_colour)'
and i'm thinking perhaps because the values of my_dict
is tuples in this case, that may be the problem?
perhaps to work around this i should make two dicts; one for bg and one for text.
but this would mean entering twice as many **kwargs into my function, and i would prefer not to do that.
Thanks in advance for any answers.