Deutsch   English   Français   Italiano  
<v4n1uh$40n6$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: David Brown <david.brown@hesbynett.no>
Newsgroups: comp.lang.c
Subject: Re: Whaddaya think?
Date: Sun, 16 Jun 2024 17:56:01 +0200
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <v4n1uh$40n6$1@dont-email.me>
References: <666ded36$0$958$882e4bbb@reader.netnews.com>
 <20240616015649.000051a0@yahoo.com> <v4lm16$3s87h$4@dont-email.me>
 <v4lmso$3sl7n$1@dont-email.me> <877cep4j2i.fsf@nosuchdomain.example.com>
 <v4lqjc$3t9au$1@dont-email.me>
 <666f000a$1$1412891$882e4bbb@reader.netnews.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 16 Jun 2024 17:56:02 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="efa9642fc1579e8fdfcdda80d78f3954";
	logging-data="131814"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+Z1u/vcp7MhT1s/EcKmiWLECaEXAdM5AU="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:B8MnxsGJeGvPC95Iygcvi/ClSqs=
In-Reply-To: <666f000a$1$1412891$882e4bbb@reader.netnews.com>
Content-Language: en-GB
Bytes: 2607

On 16/06/2024 17:09, DFS wrote:
> On 6/16/2024 12:44 AM, Janis Papanagnou wrote:
>> On 16.06.2024 06:17, Keith Thompson wrote:
>>>
>>> For the original problem, where the input consists of digits and
>>> whitespace, you could read a character at a time and accumulate the
>>> value of each number.  (You probably want to handle leading signs as
>>> well, which isn't difficult.)
>>
>> Yes. Been there, done that. Sometimes it's good enough to go back
>> to the roots if higher-level functions are imperfect or quirky.
>>
>>> That is admittedly reinventing the
>>> wheel, but the existing wheels aren't entirely round.  You still
>>> have to dynamically allocate the array of ints, assuming you need
>>> to store all of them rather than processing each value as it's read.
>>
>> A subclass of tasks can certainly process data on the fly but for
>> the general solution there should be a convenient way to handle it.
>>
>> I still prefer higher-level languages that take the burden from me.
> 
> nums = []
> with open('data.txt','r') as f:
>      for nbr in f.read().split():
>          nums.append(int(nbr))
>      print(*sorted(nums))
> 

nums = sorted(map(int, open('data.txt', 'r').read().split()))

But you'll learn more doing it with C :-)  And it's nice to see someone 
starting on-topic threads here.