Just started learning Python a month ago. I'm stumped on an issue. Trying to update a dictionary using a for loop. I would like to store the variable using the for loop's variable name as key and the variable value as the dictionary's value. I'm trying to use % to make it a one liner. Here's what I have so far:
grbl_parser_d = {
'a': 'null', # Motion Mode
'b': 'null', # Coordinate System Select
'c': 'null' # Plane Select
}
grbl_out = [GC:G0 G54 G17]
def filtergrblparser():
global grbl_parser_d
for l, r in [grbl_out.strip('[]').split(':')]:
for a, b, c in [r.split(' ')]:
# grbl_parser_d.update({'%': x}) % x
grbl_parser_d.update({'a': a})
grbl_parser_d.update({'b': b})
grbl_parser_d.update({'c': c})
The 'grbl_out' variable is the output from an Arduino.
Trying to use something like: grbl_parser_d.update({'%': a}) % a.name
'a.name' would be the for loop's variable name, not the value. Is this even possible? Any other suggestions and tips to clean up the code would also be greatly appreciated. Thanks!