I have to convert string without quotes into dictionary.
device: 0, name: GeForce GTX 1080 8GB, pci bus id: 0000:01:00.0
the 'device', 'name' and 'pci bus id' have to be keys,
and '0', 'GeForce GTX 1080 8GB', '0000:01:00.0' have to be values.
I get this from tensorflow.python.client.list_local_devices()
Using, two .split()'s and dictionary comprehension, first .split(', ') divides up the entire string, the second split(': ') divides up the items of list to be cast as keys and values
s = "device: 0, name: GeForce GTX 1080 8GB, pci bus id: 0000:01:00.0"
d = {i.split(': ')[0]: i.split(': ')[1] for i in s.split(', ')}
{'device': '0', 'name': 'GeForce GTX 1080 8GB', 'pci bus id': '0000:01:00.0'}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With