Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Random832 Newsgroups: comp.lang.python Subject: Re: Mimick tac with python. Date: Fri, 29 Jan 2016 23:58:38 -0500 Lines: 14 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de 6ejh44IjvX1NhVcxTbdeVgWjbKianvMEzseniqPO9JAw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'received:internal': 0.09; 'python': 0.10; 'jan': 0.11; 'awk': 0.16; 'constructs': 0.16; 'message-id:@webmail.messagingengine.com': 0.16; 'received:10.202': 0.16; 'received:10.202.2': 0.16; 'received:66.111': 0.16; 'received:66.111.4': 0.16; 'received:66.111.4.27': 0.16; 'received:io': 0.16; 'received:messagingengine.com': 0.16; 'received:out3-smtp.messagingengine.com': 0.16; 'received:psf.io': 0.16; 'subject:python.': 0.16; 'wrote:': 0.16; 'memory': 0.17; 'shell': 0.18; 'all,': 0.20; 'header:In-Reply-To:1': 0.24; "doesn't": 0.26; 'command': 0.26; 'fri,': 0.27; 'perl': 0.29; 'print': 0.30; 'file': 0.34; 'that,': 0.34; 'quite': 0.35; 'sometimes': 0.35; 'but': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'really': 0.37; 'received:66': 0.38; 'skip:s 40': 0.38; 'end': 0.39; 'to:addr:python.org': 0.40; 'subject:with': 0.40; 'some': 0.40; 'header:Message-Id:1': 0.61; 'more': 0.63; 'do:': 0.91 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=fastmail.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=q+fN8btAsvmOEteumV+N78w03i4=; b=IcVeMC Ib6s/0rStHCuMOdHRC+oqBaPr0ypWRVufjk1NAD/dA0xI6CDO1//9Y0OCYbVr9qI RGqyqbLNGZCGcp7MT30TX8BQVRRQnjCFYjmDxHPj63fPP6mhGjfHFn+Cgl8/YlZW GliXJcOlLSqLpnndisr6KEQ/V20sBqZgImOOU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=q+fN8btAsvmOEte umV+N78w03i4=; b=eI5o0fPQh0j2asKWbg6yskjGDQGEs0LW7WlHY97Qu5HRg9n xKE2MKAH6OGTrRjSTs8lFclUQe/0FloIdAGNwgmnHO04fkjGICayrptsIkGAnVcL gCXXENifULoKeNG7mpQqjMZD3hYng25ioGZ0jZ7mqZFkMHrrIehcehuJMCd8= X-Sasl-Enc: JmtAaDMr7jyKgf9nAF7zX/oJzBKgD1EeEl8KRPPvu+9f 1454129918 X-Mailer: MessagingEngine.com Webmail Interface - ajax-6cda141f In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:102277 On Fri, Jan 29, 2016, at 23:46, Hongyi Zhao wrote: > Hi all, > > I can use the following methods for mimicking tac command bellow: > > awk '{a[NR]=$0} END {while (NR) print a[NR--]}' input_file > perl -e 'print reverse<>' input_file Well, both of those read the whole file into memory - tac is sometimes smarter than that, but that makes for a more complex program. And python doesn't really do "one-liners" like that, so it doesn't look quite as nice. But combined with some shell constructs you can do: python <(echo 'import sys;print("".join(reversed(list(sys.stdin))))')