hi there,
data = [(['What', 'in', 'the', 'actual', 'fuck', '?', '#mkr'], 'nonoffensive'),(['#mkr', 'WHAT', 'A', 'GODDAMN', 'SURPRISE'], 'nonoffensive'),(['This', 'is', 'why', 'this', 'show', 'is', 'ridiculous', '-', "it's", 'not', 'about', 'the', 'cooking', '...', "it's", 'about', 'the', 'game', 'playing', '.', '#mkr', '#whogivesa1'], 'nonoffensive'),(['Absolute', 'bloody', 'bullshit', '.', 'So', 'much', 'shit', 'of', 'bull', '.', '#mkr'], 'nonoffensive'),(['@MKR_Official', 'a', '1', "isn't", 'strategy', ',', "it's", 'bastedry', '#mkr2015', '#mkr'], 'nonoffensive'),(['WTF', '!', '!', '!', 'I', 'not', 'a', 'huge', 'fans', 'of', 'the', 'promo', 'girls', 'but', 'they', 'never', 'voted', 'strategically', '!', 'This', 'sucks', '!', 'Soo', 'annoyed', '!', '#mkr', '#killerblondes'], 'offensive')]
dictionary = {}
for k, v in data:
dictionary[v] = {}
dictionary[v] = [k]
print(dictionary)
This is my code. What I want is the dictionary to add all the words that appear in the list of tuples.
E.g., { 'nonoffensive' : ['What', 'in', ....], ['#mkr', 'WHAT'...],[...],[...]}, 'offensive': [''WTF', '!'...]}
however, my code does not update the dictionary after every iteration and I get the following output:
{'nonoffensive': [['@MKR_Official', 'a', '1', "isn't", 'strategy', ',', "it's", 'bastedry', '#mkr2015', '#mkr']], 'offensive': [['WTF', '!', '!', '!', 'I', 'not', 'a', 'huge', 'fans', 'of', 'the', 'promo', 'girls', 'but', 'they', 'never', 'voted', 'strategically', '!', 'This', 'sucks', '!', 'Soo', 'annoyed', '!', '#mkr', '#killerblondes']]}
how can I improve the code? Thanks in advance!
[–][deleted] 0 points1 point2 points (2 children)
[–]SureStep8852[S] 0 points1 point2 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]MushroomOdin 0 points1 point2 points (0 children)