Thanks to all those who responded. It has all helped immensely. :-)
I didn't know about list comprehensions before I started.
very warm regards to all.
--
http://mail.python.org/mailman/listinfo/python-list
On 30/04/2006 12:22 AM, Max Erickson wrote:
> [EMAIL PROTECTED] wrote in
> news:[EMAIL PROTECTED]:
>
>> But this gives me "IndexError: list out of range
>
> You are making the list shorter as you are iterating. By the time your
> index is at the end of the original list, it isn't that long any
[EMAIL PROTECTED] wrote in
news:[EMAIL PROTECTED]:
> But this gives me "IndexError: list out of range
You are making the list shorter as you are iterating. By the time your
index is at the end of the original list, it isn't that long any more.
Creating a new list and appending the elements you
Ooops!
Looking at your example a bit closer, change the 'and' in the list
comprehension I posted to 'or', and it should do what you want.
--
http://mail.python.org/mailman/listinfo/python-list
This looks like a job for list comprehensions:
>>> returned_lines= ['Name: John, Value: 12','We don't want this one.','Name:
>>> Eric, Value: 24']
>>> [x for x in returned_lines if ('Name' in x and 'Value' in x)]
['Name: John, Value: 12', 'Name: Eric, Value: 24']
List comprehensions are great. I
This is python 2.4.3 on WinXP under PythonWin.
I have a config file with many blank lines and many other lines that I
don't need.
read the file in, splitlines to make a list, then run a loop that
looks like this:
config_file = open("lines.txt", "rb")
returned_lines = config_file.read().splitl