Deutsch English Français Italiano |
<666f000a$1$1412891$882e4bbb@reader.netnews.com> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!news-out.netnews.com!postmaster.netnews.com!us4.netnews.com!not-for-mail X-Trace: DXC=E7D3A\>P_<X0YeFU`>mMO^HWonT5<]0T]Q;nb^V>PUfV5[gZBW6J?L\ZHjmnLVPdB]k4G3cSPE1c_nT`JO7@`Z@PMba][>SC2CWf;]EoU=id5V=R<hY6_C9TX X-Complaints-To: support@blocknews.net Date: Sun, 16 Jun 2024 11:09:01 -0400 MIME-Version: 1.0 User-Agent: Betterbird (Windows) From: DFS <nospam@dfs.com> Subject: Re: Whaddaya think? Newsgroups: comp.lang.c 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> Content-Language: en-US In-Reply-To: <v4lqjc$3t9au$1@dont-email.me> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Lines: 27 Message-ID: <666f000a$1$1412891$882e4bbb@reader.netnews.com> NNTP-Posting-Host: 127.0.0.1 X-Trace: 1718550538 reader.netnews.com 1412891 127.0.0.1:49665 Bytes: 2128 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))