I'd like to create a table that shows the frequencies of certain words in 3 texts, whereas the texts are the columns and the words are the lines.
In the table I'd like to see which word appears how often in which text.
These are my texts and words:
texts = [text1, text2, text3]
words = ['blood', 'young', 'mercy', 'woman', 'man', 'fear', 'night', 'happiness', 'heart', 'horse']
In order to create a conditional frequency distribution I wanted to create a list of tuples that should look like lot = [('text1', 'blood'), ('text1', 'young'), ... ('text2', 'blood'), ...)
I tried to create lot like this:
lot = [(words, texte)
for word in words
for text in texts]
Instead of lot = ('text1', 'blood') etc. instead of 'text1' is the whole text in the list.
How can I create the list of tuples as intended for the conditional frequency distribution function?
Hopefully I have understood your question correctly. I think you are assigning both variable 'word' and 'texts' to their own tuple.
Try the following:
Edit: Because the change is so subtle, I should elaborate a bit more. In your original code you were setting both 'words' and 'texts' to their own tuple, ie you were assigning the whole array rather than each element of the array.