Note that there are some explanatory texts on larger screens.

plurals
  1. POFind frequency of array strings in a file sized string, using Python
    primarykey
    data
    text
    <p>I've looked at a lot of answers, which are aimed at finding the occurrence of every word in the file, or big string or even arrays. but I don't want to do this, nor are my strings coming from a text file.</p> <p>Given a big string, like a file sized string how would you count the frequency of each array element in the big string - including spaces within words?</p> <pre><code>def calculate_commonness(context, links): c = Counter() content = context.translate(string.maketrans("",""), string.punctuation).split(None) for word in content: if word in links: c[word] += 1 print c context = "It was November. Although it was November November November Passage not yet late, the sky was dark when I turned into Laundress Passage. Father had finished for the day, switched off the shop lights and closed the shutters; but so I would not come home to darkness he had left on the light over the stairs to the flat. Through the glass in the door it cast a foolscap rectangle of paleness onto the wet pavement, and it was while I was standing in that rectangle, about to turn my key in the door, that I first saw the letter. Another white rectangle, it was on the fifth step from the bottom, where I couldn\'t miss it." links = ['November', 'Laundress', 'Passage', 'Father had'] # My output should look (something) like this: # November = 4 # Laundress = 1 # Passage = 2 # Father had = 1 </code></pre> <p>At the moment it's finding November, Laundress and Passage but not 'Father had'. I need to be able to find string elements with spaces. I know this is because I'm splitting the context by " " which is returning "Father" "had", so how do I split context appropriately or do I use this with regex findall? </p> <p>EDIT: Using context as a big string I have:</p> <pre><code> for l in links: c[l] = context.lower().count(l) print c </code></pre> <p>returns:</p> <pre><code>Counter({'Laundress': 0, 'November': 0, 'Father had': 0, 'Passage': 0}) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload