Note that there are some explanatory texts on larger screens.

plurals
  1. POstring matching replace with case sensitive in python
    primarykey
    data
    text
    <p>I am quite new in python &amp; trying to do some new stuff.I have two list in a dictionary.Let's say,</p> <pre><code>List1: List2: Anterior cord cuneate nucleus Medulla oblongata nucleus Spinal cord Intermediolateral nucleus Spinal sksdsj british 7 </code></pre> <p>And I have some text lines as below:</p> <pre><code>&lt;s id="5239778-2"&gt;The name refers collectively to the cuneate nucleus and gracile nucleus, which are present at the junction between the spinal cord and the medulla oblongata.&lt;/s&gt; &lt;s id="3691284-1"&gt;In the medulla oblongata, the arcuate nucleus is a group of neurons located on the anterior surface of the medullary pyramids.&lt;/s&gt; &lt;s id="21120-99"&gt;Anterior horn cells, motoneurons located in the spinal.&lt;/s&gt; &lt;s id="1053949-16"&gt;The Anterior cord syndrome results from injury to the anterior part of the spinal cord, causing weakness and loss of pain and thermal sensations below the injury site but preservation of proprioception that is usually carried in the posterior part of the spinal cord.&lt;/s&gt; &lt;s id="69-7"&gt;...Meanwhile is the studio 7 album by British pop band 10cc.&lt;/s&gt; </code></pre> <p>I have to get return those line whose belongs string both from list1 &amp; list2.So,I have tried with the following code:</p> <pre><code>result = "" if list1 in line and list2 in line: i1 = re.sub('(?i)(\s+)(%s)(\s+)'%list1, '\\1&lt;e1&gt;\\2&lt;/e1&gt;\\3', line) i2 = re.sub('(?i)(\s+)(%s)(\s+)'%list2, '\\1&lt;e2&gt;\\2&lt;/e2&gt;\\3', i1) result = result + i2 + "\n" continue </code></pre> <p>But I am getting the following result:</p> <pre><code>&lt;s id="5239778-2"&gt;The name refers collectively to the &lt;e1&gt;cuneate nucleus&lt;/e1&gt; and gracile nucleus, which are present at the junction between the spinal cord and the medulla oblongata.&lt;/s&gt; &lt;s id="3691284-1"&gt;In the medulla oblongata, the arcuate &lt;e1&gt;nucleus&lt;/e1&gt; is a group of neurons located on the anterior surface of the medullary pyramids.&lt;/s&gt; &lt;s id="21120-99"&gt;Anterior horn cells, motoneurons located in the spinal.&lt;/s&gt; &lt;s id="1053949-16"&gt;The &lt;e1&gt;Anterior&lt;/e1&gt; &lt;e2&gt;cord&lt;/e2&gt; syndrome results from injury to the &lt;e1&gt;anterior&lt;/e1&gt; part of the spinal cord, causing weakness and loss of pain and thermal sensations below the injury site but preservation of proprioception that is usually carried in the posterior part of the spinal cord.&lt;/s&gt; &lt;s id="69-7"&gt;...Meanwhile is the studio 7 album by British pop band 10cc.&lt;/s&gt; </code></pre> <p>Here,Only the result line-4, I got that matches string from both list that is what I want.But, I don't want to get those line which match only one or no string(eg. result line-1 &amp; 3).Also,if matches string from both list , should it tag them(eg. result line-2). </p> <p>Any kind of help will be greatly appreciated.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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