import pickle target_file = './counters_Amazon_merchandise.pkl' (categories, counters) = pickle.load(open(target_file, 'rb')) print(categories) print(counters) with open('categories.txt', 'wt') as foo: for counter, category in zip(counters, categories): foo.write(f'{category}\t{counter["1"]}\t{counter["2"]}\t{counter["3"]}\t{counter["4"]}\t{counter["5"]}\n')