Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.037 X-Spam-Evidence: '*H*': 0.93; '*S*': 0.00; '%s"': 0.07; 'calls.': 0.07; 'missed': 0.09; 'backwards': 0.09; 'iterate': 0.09; 'suggest': 0.11; ':-)': 0.13; 'backward': 0.16; 'blocks': 0.16; 'forward:': 0.16; "function's": 0.16; 'wrote:': 0.17; '(or': 0.18; 'to:name:python-list@python.org': 0.20; 'file.': 0.20; "i'd": 0.22; 'sets': 0.23; "i've": 0.23; 'second': 0.24; 'header:In- Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'charset:iso-8859-15': 0.26; 'functions.': 0.27; 'loop,': 0.29; 'could': 0.32; 'print': 0.32; 'certain': 0.33; 'to:addr:python- list': 0.33; 'front': 0.33; 'thanks': 0.34; 'list': 0.35; 'faster': 0.35; 'there': 0.35; 'but': 0.36; 'subject: (': 0.36; 'level': 0.37; 'two': 0.37; 'being': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'subject:-': 0.40; 'lower': 0.61; 'first': 0.61; 'back': 0.62; 'forward': 0.66; 'reviewed': 0.74; 'dict,': 0.84; 'more:': 0.84; 'received:213.150': 0.84; 'subject:Fast': 0.84; 'subject:read': 0.84; 'subject:write': 0.84; 'average': 0.93 X-SENDER-IP: [213.112.50.224] X-LISTENER: [smtp.bredband.net] X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Aj4mAMOSh1DVcDLgPGdsb2JhbAANN4pOt0YBAQEBOIJSAQEBAQM4QBELGAkWDwkDAgECATEUBg0IAQGvSZNFi2CGawOpHQ X-IronPort-AV: E=Sophos;i="4.80,639,1344204000"; d="scan'208";a="212096543" Date: Wed, 24 Oct 2012 09:05:38 +0200 From: Virgil Stokes User-Agent: Mozilla/5.0 (Windows NT 6.0; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: "python-list@python.org" Subject: Re: Fast forward-backward (write-read) References: <5086AA35.4000509@it.uu.se> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1351062335 news.xs4all.nl 6946 [2001:888:2000:d::a6]:47802 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:32009 On 24-Oct-2012 00:36, David Hutto wrote: >> Don't forget to use timeit for an average OS utilization. >> >> I'd suggest two list comprehensions for now, until I've reviewed it some more: >> >> forward = ["%i = %s" % (i,chr(i)) for i in range(33,126)] >> backward = ["%i = %s" % (i,chr(i)) for i in range(126,32,-1)] >> >> for var in forward: >> print var >> >> for var in backward: >> print var >> >> You could also use a dict, and iterate through a straight loop that >> assigned a front and back to a dict_one = {0 : [0.100], 1 : [1.99]} >> and the iterate through the loop, and call the first or second in the >> dict's var list for frontwards , or backwards calls. >> >> >> But there might be faster implementations, depending on other >> function's usage of certain lower level functions. >> > Missed the part about it being a file. Use: > > forward = ["%i = %s" % (i,chr(i)) for i in range(33,126)] > backward = ["%i = %s" % (i,chr(i)) for i in range(126,32,-1)] > > print forward,backward Interesting approach for small data sets (or blocks from a much larger data set). Thanks David :-)