3
Contributors
12
Replies
13
Views
6 Years
Discussion Span
Last Post by pyTony
0

You must first find a way to split the text into a list of paragraphs, each containing a principle.

Edited by Gribouillis: n/a

0

You must first find a way to split the text into a list of paragraphs, each containing a principle.

Could use an example if you have one.
Code is easier to understand.

0

For example, using re.split()

import re

pat = re.compile(r"\n(?=\d)") # matches newline followed by a digit

text = """\


1.	Principle of Segmentation:
   	a) Divide an object into independent parts
                 - Replace a large truck by a truck and trailer.
                 - Use a work breakdown structure for a large project.
                 - Sequential novel turn into movies
                 
	b) Make an object easy to disassemble.
		 - Bicycle disassembling (saddle, wheels)
		 - Furniture (sofas, table)
		 - Crib
        c) Increase the degree of fragmentation or segmentation.
                 - Replace solid shades with Venetian blinds
                 - Computer covers with holes for ventilation
		 - Multi blade cartridge Razor


4.	Principle of Asymmetry:
        a.	If an object is symmetrical, change its shape to irregular.
                -Asymmetric paddles mix 
                -cement 
                -truck 
                -blender
                -cake mixer

"""
paragraphs = pat.split(text)

for p in paragraphs:
    print "******* PARAGRAPH *********"
    print p
    
print "THERE ARE %d paragraphs" % len(paragraphs)

My output:

******* PARAGRAPH *********


******* PARAGRAPH *********
1.	Principle of Segmentation:
   	a) Divide an object into independent parts
                 - Replace a large truck by a truck and trailer.
                 - Use a work breakdown structure for a large project.
                 - Sequential novel turn into movies
                 
	b) Make an object easy to disassemble.
		 - Bicycle disassembling (saddle, wheels)
		 - Furniture (sofas, table)
		 - Crib
        c) Increase the degree of fragmentation or segmentation.
                 - Replace solid shades with Venetian blinds
                 - Computer covers with holes for ventilation
		 - Multi blade cartridge Razor


******* PARAGRAPH *********
4.	Principle of Asymmetry:
        a.	If an object is symmetrical, change its shape to irregular.
                -Asymmetric paddles mix 
                -cement 
                -truck 
                -blender
                -cake mixer


THERE ARE 3 paragraphs

Edited by Gribouillis: n/a

0

Thanks, so now to match the word to the cpresponding paragraph i should make a "if true" statemant or something along those lines?

0

Thanks, so now to match the word to the cpresponding paragraph i should make a "if true" statemant or something along those lines?

One way is to search the pattern in each of the paragraphs in the list instead of the whole text.

0

One way is to search the pattern in each of the paragraphs in the list instead of the whole text.

Do you mean something like this?

data = [['a','b'], ['a','c'], ['b','d']]
search = 'c'
for sublist in data:
    if sublist[1] == search:
       print "Found it!", sublist
       break
0

Do you mean something like this?

data = [['a','b'], ['a','c'], ['b','d']]
search = 'c'
for sublist in data:
    if sublist[1] == search:
       print "Found it!", sublist
       break

Rather something like

import re
data = ["One way is to search the pattern", "in each of the paragraphs in the list", "instead of the whole text."] 

for subtext in data:
    if re.search(r"\blist\b", subtext, re.I):
        print "FOUND", subtext

Edited by Gribouillis: n/a

0

Rather something like

import re
data = ["One way is to search the pattern", "in each of the paragraphs in the list", "instead of the whole text."] 

for subtext in data:
    if re.search(r"\blist\b", subtext, re.I):
        print "FOUND", subtext

Sorry i dont understand what you are trying to tell me there.
Am i ment to but the Principles in data between the " ",
Because i have tried, with no avail.

0

Rather something like

import re
data = ["One way is to search the pattern", "in each of the paragraphs in the list", "instead of the whole text."] 

for subtext in data:
    if re.search(r"\blist\b", subtext, re.I):
        print "FOUND", subtext

Sorry to bother you agin but i got another question.
Lets ay i wanted to assign a bunch of words to each princile, that if searched for would triggr the principle but NOT display the word/s.

0

Re: I just got your code :).

Not sure which piece of my code you refered. I have written a few :icon_cheesygrin:

Edited by pyTony: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.