Reading selected data from text files

..:: sjf ::.. sjf at autograf.pl
Mon Mar 1 10:34:22 EST 2004


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?


--
..:: sjf ::..
"Linux is like Wigwam. No gates, no windows... Apache inside ;-)"




More information about the Python-list mailing list