Note that there are some explanatory texts on larger screens.

plurals
  1. POConvert list into sub-list while maintaining "key"
    text
    copied!<p>I have a list that contains a 'key' and 'paragraph'. Each 'key' is associated with a 'paragraph'.</p> <p>My goal is to break each paragraph into individual sentences, with each sentence being assign to the 'key' they originally belonged to in paragraph form. For example:</p> <pre><code>(['2925729', 'Patrick came outside and greeted us promptly.'], ['2925729', 'Patrick did not shake our hands nor ask our names. He greeted us promptly and politely, but it seemed routine.'], ['2925728', 'Patrick sucks. He farted politely, but it seemed routine.']) </code></pre> <p>Right now I've been able to write code to break out sentences into paragraphs, and get the number of hits for each sentence against a dictionary. I now want to associate an ID to each question.</p> <p>Here is the code that deals with sentences without any 'key'. Step1 and 2 I omitted for space conservation: </p> <pre><code>Dictionary = ['book', 'should have', 'open'] ####Step3##### #Create Blank list to append final output final_out = [] ##Find Matches for sent in sentences: for sent in sentences: final_out.append((sent, sum(sent.count(col) for col in dictionary))) #####Spit out final distinct output ##Output in dictionary structure final_out = dict(sorted(set(final_out))) ####Get sentences and rank by max first import operator sorted_final_out = sorted(final_out.iteritems(),key = operator.itemgetter(1), reverse = True) </code></pre> <p>The output from this is: <strong><em>(['johny ate the antelope', 80], ['sally has a friend',20])</em></strong> and so on. I then pick the top X b magnitude. What I am now trying to achieve is something like this: <strong>(['12222','johny ate the antelope', 80], [22332,'sally has a friend',20])</strong>. So i basically want to ensure that all sentences when parsed out are assigned to a 'key'. This is complicated sorry. Again that is why John's earlier solution would work on a simpler case.</p>
 

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