Pete O'Connell wrote:
> Hi, I have tried to simplify things and am running into a bit of trouble.
> What i am really trying to do is: Keep all the lines starting with "v "
> and then delete those lines whose modulus 5 don't equal zero
>
> I have written it like this which seems to take a really l
(you replied off-list, so I'm cc'ing the list here, to keep it public)
On 08/23/2012 10:42 PM, Pete O'Connell wrote:
> On Fri, Aug 24, 2012 at 1:39 PM, Dave Angel wrote:
>
>> On 08/23/2012 09:11 PM, Pete O'Connell wrote:
>>> Hi, I have tried to simplify things and am running into a bit of troubl
On 08/23/2012 10:34 PM, eryksun wrote:
> On Thu, Aug 23, 2012 at 9:39 PM, Dave Angel wrote:
>>
>>> theGoodLines = [line.strip("\n") for line in lines if "v " ==
>>> line[0:2]]
>>
>> Better to use startswith(), since short lines will cause the if
>> expression above to blow up.
>
> A slice won
On Thu, Aug 23, 2012 at 9:39 PM, Dave Angel wrote:
>
>> theGoodLines = [line.strip("\n") for line in lines if "v " ==
>> line[0:2]]
>
> Better to use startswith(), since short lines will cause the if
> expression above to blow up.
A slice won't blow up. At worst you get an empty string. But t
On 08/23/2012 09:11 PM, Pete O'Connell wrote:
> Hi, I have tried to simplify things and am running into a bit of trouble.
> What i am really trying to do is: Keep all the lines starting with "v " and
> then delete those lines whose modulus 5 don't equal zero
>
> I have written it like this which se
Hi, I have tried to simplify things and am running into a bit of trouble.
What i am really trying to do is: Keep all the lines starting with "v " and
then delete those lines whose modulus 5 don't equal zero
I have written it like this which seems to take a really long time (a
couple of minutes wh
On Thu, Aug 23, 2012 at 2:57 AM, Pete O'Connell wrote:
> On Thu, Aug 23, 2012 at 4:16 AM, Alan Gauld wrote:
>
>> theTextAsListNoVnOrVtOrEmptyLine = [x for x in theTextAsListStripped
>> if "vn" not in x
>>
Ok thanks for the advice everyone.
Cheers
Pete
On Thu, Aug 23, 2012 at 10:58 AM, Jerry Hill wrote:
> On Wed, Aug 22, 2012 at 5:23 PM, Pete O'Connell
> wrote:
>> OK maybe I am wrong about it being slow (I thought for loops were
>> slower than lis comprehensions). But I do know I need it to be a
On Wed, Aug 22, 2012 at 5:23 PM, Pete O'Connell wrote:
> OK maybe I am wrong about it being slow (I thought for loops were
> slower than lis comprehensions). But I do know I need it to be as fast
> as possible if I need to run it on a thousand files each with hundreds
> of thousands of lines
You'
On 22/08/12 22:23, Pete O'Connell wrote:
What makes you say it is "terribly slow"? Perhaps it is as fast as it
could be under the circumstances. (Maybe it takes a long time because
you have a lot of data, not because it is slow.)
OK maybe I am wrong about it being slow (I thought for loops wer
rg
>Sent: Wednesday, 22 August 2012, 22:27
>Subject: Re: [Tutor] list comprehension, testing for multiple conditions
>
>On Thu, Aug 23, 2012 at 4:16 AM, Alan Gauld wrote:
>
>> theTextAsListNoVnOrVtOrEmptyLine = [x for x in theT
On 22/08/2012 22:23, Pete O'Connell wrote:
On Thu, Aug 23, 2012 at 2:53 AM, Steven D'Aprano wrote:
Further to Steven's sound advice take a look at this
http://wiki.python.org/moin/PythonSpeed/PerformanceTips IMHO the part
on profiling is particulary useful.
--
Cheers.
Mark Lawrence.
___
On Thu, Aug 23, 2012 at 4:16 AM, Alan Gauld wrote:
> theTextAsListNoVnOrVtOrEmptyLine = [x for x in theTextAsListStripped
> if "vn" not in x
> if "vt" not in x
>
On Thu, Aug 23, 2012 at 2:53 AM, Steven D'Aprano wrote:
> On 22/08/12 20:28, Pete O'Connell wrote:
>>
>> Hi. The next step for me to parse the file as I want to is to change
>> lines that look like this:
>> f 21/21/21 22/22/22 24/24/23 23/23/24
>> into lines that look like this:
>> f 21 22 23 24
>
Thanks eryksun, that is a very clear example.
Cheers
pete
On Wed, Aug 22, 2012 at 11:16 PM, eryksun wrote:
> On Wed, Aug 22, 2012 at 3:06 AM, Peter Otten <__pete...@web.de> wrote:
>>
>> wanted = [line.strip("\n") for line in lines
>> if "vn" not in line and "vt" not in line a
On 22/08/12 10:51, Pete O'Connell wrote:
theTextAsListNoVnOrVtOrEmptyLine = [x for x in theTextAsListStripped if "vn" not in x and
"vt" not in x and x!= ""]
It works but what I don't understand about this line is why the ands
are not ors
Because 'or' would include x if any one of the condi
On 22/08/12 20:28, Pete O'Connell wrote:
Hi. The next step for me to parse the file as I want to is to change
lines that look like this:
f 21/21/21 22/22/22 24/24/23 23/23/24
into lines that look like this:
f 21 22 23 24
In English, what is the rule you are applying here? My guess is:
"Given t
Pete O'Connell wrote:
[Please don't to-post. Clip all text of previous posts except the portion
relevant to your question]
> Hi. The next step for me to parse the file as I want to is to change
> lines that look like this:
> f 21/21/21 22/22/22 24/24/23 23/23/24
> into lines that look like this:
On Wed, Aug 22, 2012 at 3:06 AM, Peter Otten <__pete...@web.de> wrote:
>
> wanted = [line.strip("\n") for line in lines
> if "vn" not in line and "vt" not in line and line != "\n"]
Here's an equivalent expression with the negation factored out:
not ("vn" in line or "vt"
Hi. The next step for me to parse the file as I want to is to change
lines that look like this:
f 21/21/21 22/22/22 24/24/23 23/23/24
into lines that look like this:
f 21 22 23 24
Below is my terribly slow loop for doing this. Any suggestions about
how to make this code more efficient would be gre
Thanks Peter. This looks like what I need:
with open(fileName) as lines:
wanted = [line.strip("\n") for line in lines if "vn" not in line
and "vt" not in line and line != "\n"]
Cheers
And in response to Allan's suggestion. I can see using a generator in
a situation where the if statements we
What a great mailing list!
Thanks for all the responses.
I have a few questions, though, first in regards to Puneeth's code. He
writes to use:
>theTextAsListNoVnOrVtOrEmptyLine = [x for x in theTextAsListStripped if "vn"
>not in x and "vt" not in x and x!= ""]
It works but what I don't understa
On 22/08/2012 07:29, Johann Spies wrote:
#start
import re
exclude = re.compile('vn|vt|^$|^#')
fileName = '/tmp/x'
theFileOpened = open(fileName,'r')
theTextAsList = theFileOpened.readlines()
theTextAsListStripped = []
for aLine in theTe
On 22/08/12 08:06, Peter Otten wrote:
You can even have multiple if clauses in one list-comp (but that is rarely
used):
with open(filename) as lines:
wanted = [line.strip("\n") for line
if "vn" not in line
if "vt" not in x
if line !=
Pete O'Connell wrote:
> Hi I am trying to parse a text file and create a list of all the lines
> that don't include: "vn", "vt" or are empty. I want to make this as
> fast as possible because I will be parsing many files each containing
> thousands of lines. I though I would give list comprehensio
#start
import re
exclude = re.compile('vn|vt|^$|^#')
fileName = '/tmp/x'
theFileOpened = open(fileName,'r')
theTextAsList = theFileOpened.readlines()
theTextAsListStripped = []
for aLine in theTextAsList:
theTextAsListStripped.append
Hi I am trying to parse a text file and create a list of all the lines
that don't include: "vn", "vt" or are empty. I want to make this as
fast as possible because I will be parsing many files each containing
thousands of lines. I though I would give list comprehensions a try.
The last 3 lines of t
27 matches
Mail list logo