Reading selected data from text files

Paul McGuire ptmcg at users.sourceforge.net
Mon Mar 1 12:32:00 EST 2004


"..:: sjf ::.." <sjf at autograf.pl> wrote in message
news:c1vl6l$lle$1 at atlantis.news.tpi.pl...
> U¿ytkownik "Paul McGuire" <ptmcg at users.sourceforge.net> napisa³ w
wiadomo¶ci
> news:MVK%b.7974$lS1.1103 at fe2.texas.rr.com...
> > "..:: sjf ::.." <sjf at autograf.pl> wrote in message
> > news:c1njho$adr$1 at nemesis.news.tpi.pl...
> > > Hello Pythoners!
> > >
> > > There are a lot of files containing data such as:
> > >
> > > file1:
> > > 0950 1550
> > >
> > > file22:
> > > 0952 1552
> > >
> > <snip>
> > > --
> > > ..:: sjf ::..
> > > "Linux is like Wigwam. No gates, no windows... Apache inside ;-)"
> > Try this:
> >
> > import sets
> > import os
> >
> > uniqueElems = sets.Set()
> >
> > testdata = """
> > 0950 1550
> > 0952 1552
> > 1000 1020 1050 1130 1150 1200 1245 1600
> > 1002 1022 1052 1132 1152 1202 1247 1602
> > 1005 1025 1055 1135 1155 1205 1250 1605
> > """
> > for line in testdata.split("\n"):
> >     uniqueElems.update( line.split() )
> >     # if running Python 2.3.1 or later, replace previous line with
> >     # uniqueElems |= line.split()
>                              ^^^^^^^
> OK, but what is that?
>
>
In 2.3.1, the Set() class defines a "|=" operator that will add all elements
of a list to the set.

Also, update() is deprecated in 2.3.1 in favor of union_update(),
intersection_update(), and, um, some other update() that I can't recall off
the top of my head, something like "negative_intersection_update" or
something.

-- Paul





More information about the Python-list mailing list