I'm new to Python and struggling to get my head around lists and dictionaries, specifically accessing specific fields.
I am trying to capture and keep track of Bluetooth mac addresses so I have created a list of dictionaries, which is as close to the C concept of an array of structs as I can manage:
max_devices = 10
num_devices = 2
device_params = {'device_number','device_id','device_mac'}
devices = [device_params] * num_devices
For testing purposes I then create a couple of dummy dictionary entries:
devices[0] = {0, "zero", "00aa00bb00cc"}
devices[1] = {1, "one", "00dd00ee00ff"}
I can print out the entire dictionary for each device, one at a time:
print("Devices, 1 by 1:")
which_device = devices[0]
print(which_device)
which_device = devices[1]
print(which_device)
Straightforward, but why are they being printed out of sequence?, i.e.
Devices, 1 by 1:
{0, 'zero', '00aa00bb00cc'}
{'00dd00ee00ff', 1, 'one'}
That is an aside though. The main problem is that I've come unstuck by trying to incorporate printing specific dictionary fields into a loop:
print("Devices, looped:")
for device in devices:
print("device_mac" in devices)
I've tried a lot of combinations for the final print command but nothing so far has worked and I am now going around in circles. I want to loop through each dictionary and print out a specific item such as "device_mac".
The next step is to add some dummy devices but it would be prudent for me to get past this bit first. I'd be grateful for some direction here.