First you need to create a dictionary. Keys are unique, if you want to store multiple values under one key, store a list as value. Then draw from it:
tasktotal = ["Medbay/Submit Scan","Medbay/Submit Example","Cafeteria/Connect Wire", "Electrical/Connect Wire","Cafeteria/Empty Garbage", "Security/Connect Wire","Navigation/Navigate", "Upper Engine/Fuel","Lower Engine/Fuel","Shield/Prime Shield", "Storage/Empty Garbage","Admin/Swipe Card","Weapon/Clear Asteroid", "Admin/Connect Wire","Storage/Connect Wire"] # import defaultdict # d = defaultdict(list) # instead of d={} and then simply use d[key].append(...) it creates # the list itself data = {} for task in tasktotal: key, value = task.split("/") # either use plain dict and test key yourself if key in data: data[key].append(value) else: data[key] = [value] # or use setdefault # d.setdefault(key,[]).append(value) # or # d[key].append(...) with defaultdict(list) print(data)
Then query randomly:
import random # random key/value-list pair key,values = random.choice(list(data.items())) # random item from value-list print(key, "->", random.choice(values))
Output:
'edbay': ['Submit Scan', 'Submit Example'], 'Cafeteria': ['Connect Wire', 'Empty Garbage'], 'Electrical': ['Connect Wire'], 'Security': ['Connect Wire'], 'Navigation': ['Navigate'], 'Upper Engine': ['Fuel'], 'Lower Engine': ['Fuel'], 'Shield': ['Prime Shield'], 'Storage': ['Empty Garbage', 'Connect Wire'], 'Admin': ['Swipe Card', 'Connect Wire'], 'Weapon': ['Clear Asteroid']} Lower Engine -> Fuel
You could have combined answers to these 2 questions to selfanswer yours:
random.choice(my_list). We can't answer your question about dictionaries, because you haven't shown us an example.