Liam Clarke wrote:
print [w for w in j.split() if w[0] == '*' and w[-1] == '*']
Wouldn't that only work if it was bug *car* jeff?
I can imagine bug*car*jeff would throw it.
Cheers,
Liam Clarke
x = 'bug*car*jeff*foo*bar'
[x.split('*')[a] for a in range(1,len(x.split('*')), 2)]
When you mix * and
print [w for w in j.split() if w[0] == '*' and w[-1] == '*']
Wouldn't that only work if it was bug *car* jeff?
I can imagine bug*car*jeff would throw it.
Cheers,
Liam Clarke
--
'There is only one basic human right, and that is to do as you damn well please.
And with it comes the only basic
Damn!
C&P-bug here to! Is this a virus? ;-)
print [w for w in j.split() if words[0] == '*' and words[-1] == '*']
Should be:
print [w for w in j.split() if w[0] == '*' and w[-1] == '*']
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman
Liam Clarke wrote:
x= ["Dude", 'How is it going man', ' ']
print x
['Dude', 'How is it going man', ' ']
j=[]
for item in x:
... if re.search('\S+',item):
... j.append(item)
print j
['Dude', 'How is it going man']
What about:
x= ["Dude", 'How is it going man', ' ']
>>> x= ["Dude", 'How is it going man', ' ']
>>> print x
['Dude', 'How is it going man', ' ']
>>> j=[]
>>> for item in x:
... if re.search('\S+',item):
... j.append(item)
>>> print j
['Dude', 'How is it going man']
Now, I first did that in a Perl script, but it easily come
Wolfram Kraus a écrit :
Liam Clarke wrote:
regexes are common across a lot of languages, even Java has them.
Though the pain that would be I daren't not imagine. So the syntax is
familiar, whereas string methods may not be.
But IMHO string methods are (more) explicit and readable, the name tells
Liam Clarke wrote:
regexes are common across a lot of languages, even Java has them.
Though the pain that would be I daren't not imagine. So the syntax is
familiar, whereas string methods may not be.
But IMHO string methods are (more) explicit and readable, the name tells
you what the method is
regexes are common across a lot of languages, even Java has them.
Though the pain that would be I daren't not imagine. So the syntax is
familiar, whereas string methods may not be.
On Wed, 09 Feb 2005 09:00:52 +0100, Wolfram Kraus
<[EMAIL PROTECTED]> wrote:
> Ron Nixon wrote:
> > Can anyone tell
Ron Nixon wrote:
Can anyone tell me what I've done wrong in this
script.
I'm trying to get only the lines that start with
"This" for a text file.
Here's what I wrote:
import re
f = open('c:/lines.txt').readlines()
for line in f:
match = re.search('^This',f)
if line == match: