I am experimenting with python and getting stuck trying to understand error messages in the context of what I'm doing.
I play with understanding and try to find a template for creating an understanding of a list / dictionary with more than one set of input (if possible):
Note: Here, a set of input words means an understanding input area. In setbuilder notation, where python came up with its interpretations [Y for X in LIST], Y is the output function, X is the variable, and LIST is the set of input.
Suppose I have the following working code:
from random import randint mydict = {k: 0 for k in range(10)} result = {randint(0,9): v + 1 for v in mydict.values()}
I am not trying to do something special. This is not even useful code, because it will not work as expected. All elements in the dictionary will have a value of 1, and not just those pointed to by a random generator. My only goal is to get the foundation from where I start my attempt to work with a tuple of input sets.
from random import randint mydict = {k: 0 for k in range(10)} result = {k: v + 1 for k, v in (randint(0,9), mydict.values())}
This parameter gives me: TypeError: 'int' object is not iterable .
Replacing the input sets and unpacking, I:
result = {k: v + 1 for *v, k in (mydict.values(), randint(0,9))}
But this option gives me: TypeError: can only concatenate list (not "int") to list
Do these errors appear because I'm trying to do something that the language grammar does not understand, or am I missing something, and could I really fix the code?