Peter Otten a écrit :
> Bruno Desthuilliers wrote:
>
>> # You don't need to read the whole file in memory
>
>> lines1, lines2 = tee(infile)
>> print min(extract_numbers(lines1)), max(extract_numbers(lines2))
>
> tee() internally maintains a list of items that were seen by
> one but not all of th
Bruno Desthuilliers wrote:
> # You don't need to read the whole file in memory
> lines1, lines2 = tee(infile)
> print min(extract_numbers(lines1)), max(extract_numbers(lines2))
tee() internally maintains a list of items that were seen by
one but not all of the iterators returned. Therefore after
Bruno Desthuilliers a écrit :
(snip)
> # Notice that here, b is a string, not a number...
> try:
> b = int(tmp[1])
oops, I meant:
b = float(tmp[1])
Idem here:
> def extract_number(iterable):
> for linenum, line in enumerate(iterable):
> try:
>
Chris a écrit :
> On Dec 4, 2:14 pm, Horacius ReX <[EMAIL PROTECTED]> wrote:
>> Hi, I have a text file like this;
>>
>> 1 -33.453579
>> 2 -148.487125
>> 3 -195.067172
>> 4 -115.958374
>> 5 -100.597841
>> 6 -121.566441
>> 7 -121.025381
>> 8 -132.103507
>> 9 -108.939327
>> 10 -97.046703
>> 11 -52.866
> Your regex is not working correctly I guess, I don't even know why you
> are using a regex, something like this would work just fine:
>
> import sys
> nums = [float(line.split(' -')[1]) for line in open(sys.argv[1])]
> print 'min=', min(nums), 'max=', max(nums)
Sorry, that should be line.split
> Horacius ReX <[EMAIL PROTECTED]> (HR) wrote:
>HR> while 1:
>HR> line = infile1.readline()
You have an infinite loop. Fortunately your program stops because of the
error. When you encounter end of file, line becomes the empty string and
the split gives you only 1 item instead of 2.
On 2007-12-04, Horacius ReX <[EMAIL PROTECTED]> wrote:
> Hi, I have a text file like this;
>
> 1 -33.453579
> 2 -148.487125
> 3 -195.067172
> 4 -115.958374
> 5 -100.597841
> 6 -121.566441
> 7 -121.025381
> 8 -132.103507
> 9 -108.939327
> 10 -97.046703
> 11 -52.866534
> 12 -48.432623
> 13 -112.79041
> Hi, I have a text file like this;
>
> 1 -33.453579
> 2 -148.487125
>
>
> So I want to write a program in python that reads each line and
> detects which numbers of the second column are the maximum and the
> minimum.
>
> I tried with;
>
> import os, sys,re,string
>
> # first parameter is the
On Dec 4, 2:14 pm, Horacius ReX <[EMAIL PROTECTED]> wrote:
> Hi, I have a text file like this;
>
> 1 -33.453579
> 2 -148.487125
> 3 -195.067172
> 4 -115.958374
> 5 -100.597841
> 6 -121.566441
> 7 -121.025381
> 8 -132.103507
> 9 -108.939327
> 10 -97.046703
> 11 -52.866534
> 12 -48.432623
> 13 -112.7
Hi, I have a text file like this;
1 -33.453579
2 -148.487125
3 -195.067172
4 -115.958374
5 -100.597841
6 -121.566441
7 -121.025381
8 -132.103507
9 -108.939327
10 -97.046703
11 -52.866534
12 -48.432623
13 -112.790419
14 -98.516975
15 -98.724436
So I want to write a program in python that reads eac
10 matches
Mail list logo