Hello!
a = [(['192.168.0.1'], ['8080']), (['192.168.0.2'], ['4662']), (['192.168.0.3'], ['8080', '4662']), (['192.168.0.4'], ['8080', '4662']), (['192.168.0.5'], ['8080', '4662']), (['192.168.0.6'], ['8080']), (['192.168.0.8'], ['80', '443'])] Why it works like this: for key,val in a: d[key[0]] = val
This doesn't work like this: [(d[key[0]] = val) for key,val in a]
File "<stdin>", line 1 [(d[key[0]] = val) for key,val in a] ^ SyntaxError: invalid syntax Can it somehow be written shorter / prettier?
And why does [a.remove(item) for item in a if '8080' in item[1]] delete not all values ​​at once? That is, you need to run the expression several times to remove all matches.
And the most important question : Please tell me the most correct method of working with data in python of type key: value (as in the example above, but very much), so that you can then search by key, or by value and delete the found pair? At the moment I have a sheet of sheets with sheets (as in the example above), but I don’t like it by sight :) and I decided to translate it all into a dictionary, but as they say on the Internet, dictionaries are not intended for this.