# Convert dict entries to sets and lists

Can you please tell me if there is a better way to do this?

people = {'123456':{'first': 'Bob', 'last':'Smith'},
'2345343': {'first': 'Jim', 'last': 'Smith'}}

names = list()
first_names= set()
last_names = set()
for device in people:
names.append(device)


I want to get a list of IDs, and sets of first and last Names. I know this code will work, but can I improve this?

The only possible improvement I see is to avoid unnecessary dictionary lookups by iterating over key-value pairs:

ids = list()
first_names = set()
last_names = set()

for person_id, details in people.items():
ids.append(person_id)


Instead of appending the id's one by one, I would use:

ids = list(people.keys())


Note that I changed names to ids, as numbers don't seem like names to me. This is something that @jano's answer included but didn't explicitly state.

first_names = set()
last_names = set()

for details in people.values():

first_names = {v['first'] for v in people.values()}