PDA

View Full Version : esercizio in python...chi mi aiuta?


Everyman
25-10-2006, 01:42
L'esercizio e' in lingua inglese.

considerata la stringa s

s="""IBM rose 1.2% to $81.49
thanks to an upgrade to 'buy' from 'hold' from Citigroup,
but Cisco fell 0.2% to $100.02."""

con le regular expressions, come faccio a far apparire le due seguenti cose?

-words in quotes
-all words which are not numerical amounts


Io ho iniziato importando il seguente modulo:

from nltk_lite.utilities import re_show



Ma poi devo mettere l'effettiva regular expression iniziando ovviamente con:

re_show(' bla-bla :D ')


Qualcuno sa cosa devo mettere al posto del bla-bla :D ?

Vi prego, son disperato, ho provato di tutto, ma non so dove sbaglio :cry:

Gavrila
25-10-2006, 15:02
http://www.regular-expressions.info/

marco.r
25-10-2006, 17:08
http://docs.python.org/lib/module-re.html

L'esercizio e' in lingua inglese.

considerata la stringa s

s="""IBM rose 1.2% to $81.49
thanks to an upgrade to 'buy' from 'hold' from Citigroup,
but Cisco fell 0.2% to $100.02."""

con le regular expressions, come faccio a far apparire le due seguenti cose?

-words in quotes

Con o senza gli apici ?
nel primo caso qualcosa come

testo = "blablabla"
import re
re.findall("'.*?'", test )

nel secondo devi specificare che vuoi solo il contenuto:

testo = "blablabla"
import re
re.findall("'(.*?)'", test )



-all words which are not numerical amounts



import re
re.findall('[a-zA-Z]+',testo)



Io ho iniziato importando il seguente modulo:

from nltk_lite.utilities import re_show

Perche' non usare il modulo di sistema ?