473,326 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

isplit

I have a file of lines that contains some extraneous chars, this the
basic version of code to process it:

IDtable = "".join(map(chr, xrange(256)))
text = file("...", "rb").read().translate(IDtable, toRemove)
for raw_line in file(file_name):
line = raw_line.translate(IDtable, toRemove)
...
A faster alternative:

IDtable = "".join(map(chr, xrange(256)))
text = file(file_name).read().translate(IDtable, toRemove)
for line in text.split("/n"):
...

But text.split requires some memory if the text isn't small.
Probably there are simpler solutions (solutions with the language as it
is now), but one seems the following, an:

str.isplit()
or
str.itersplit()
or
str.xsplit()
Like split, but iterative.

(Or even making str.split() itself an iterator (for Py3.0), and
str.listsplit() to generate lists.)
(At the moment a simple RE can probably work as the isplit.)

Bye,
bearophile

Jan 26 '06 #1
0 963

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Ronald Legere | last post by:
The new itertools stuff is pretty cool. One thing that bothers me though is that there seems to be no way to copy an iterator. How does one work around this? Is there a trick that I am missing? ...
0
by: Konstantin Veretennicov | last post by:
Don't you think an iterator version of str.split() could be handy in some cases? You may have to split() quite a long string, but really need only one chunk at a time, not entire list at once...
4
by: Ian Sparks | last post by:
string.split() is very useful, but what if I want to split a list of integers on some element value? e.g. : >> l = >> l.split(-1) >> ,,] Here's my hideous first pass :
2
by: =?Utf-8?B?WVhR?= | last post by:
Hello, I want to convert the timespan (1.12:25:23) to 1day 12hour 25min 23sec, how to do it? thank you.
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.