If i understand correctly, the following might be along the lines of what you are looking for.
With the additional comments
method_names = ['female_condoms', 'emergency', 'male_condoms', 'pill', 'injectables', 'iud', 'male_sterilization', 'female_sterilization'] methods_discussed = [['iud', 'male_condoms', 'pill'], ['male_condoms'], [], ['female_sterilization', 'male_sterilization'], ['male_sterilization', 'iud', 'injectables']] data_points = [] for method_dicuseed in methods_discussed: points = [] for method_name in method_names: points.append(int(method_name in method_dicuseed)) data_points.append(points) print(data_points)
Output:[[0, 0, 1, 1, 0, 1, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 1], [0, 0, 0, 0, 1, 1, 1, 0]]
With the additional comments
import pprint method_names = ['female_condoms', 'emergency', 'male_condoms', 'pill', 'injectables', 'iud', 'male_sterilization', 'female_sterilization'] methods_discussed = [['iud', 'male_condoms', 'pill'], ['male_condoms'], [], ['female_sterilization', 'male_sterilization'], ['male_sterilization', 'iud', 'injectables']] data_points = [] for index, method_dicuseed in enumerate(methods_discussed): points = [index+1, method_dicuseed] for method_name in method_names: points.append(int(method_name in method_dicuseed)) data_points.append(points) pprint.pprint(data_points)
Output:[[1, ['iud', 'male_condoms', 'pill'], 0, 0, 1, 1, 0, 1, 0, 0],
[2, ['male_condoms'], 0, 0, 1, 0, 0, 0, 0, 0],
[3, [], 0, 0, 0, 0, 0, 0, 0, 0],
[4, ['female_sterilization', 'male_sterilization'], 0, 0, 0, 0, 0, 0, 1, 1],
[5, ['male_sterilization', 'iud', 'injectables'], 0, 0, 0, 0, 1, 1, 1, 0]]