Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!cs.uu.nl!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.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.021 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'skip:/ 10': 0.07; 'path)': 0.09; 'sub': 0.09; 'subject:method': 0.09; '4-digit': 0.16; 'decimal.': 0.16; 'digits.': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'int.': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'printf': 0.16; 'sense,': 0.16; 'skip:@ 20': 0.16; 'thread.': 0.16; 'wed,': 0.16; 'wrote:': 0.17; 'subject:page': 0.17; 'jan': 0.18; 'int,': 0.22; 'skip:% 10': 0.22; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; '[1]': 0.27; 'am,': 0.27; "doesn't": 0.28; 'chris': 0.28; 'cat': 0.29; 'decimal': 0.29; 'hash': 0.29; 'perl': 0.29; 'yes.': 0.29; 'convert': 0.29; 'read,': 0.29; 'probably': 0.29; 'asking': 0.32; 'problem.': 0.32; 'could': 0.32; 'int': 0.33; 'subject: .': 0.33; 'to:addr:python-list': 0.33; 'offered': 0.35; 'something': 0.35; 'there': 0.35; 'but': 0.36; 'anything': 0.36; 'enough': 0.36; 'data': 0.37; 'subject:: ': 0.38; 'sure': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; "you've": 0.61; 'chance': 0.61; 'free': 0.61; 'back': 0.62; 'different': 0.63; 'header:Reply-To:1': 0.68; '8bit%:100': 0.70; '8bit%:92': 0.70; 'reply-to:no real name:2**0': 0.72; 'guaranteed': 0.76; '2013': 0.84; 'remarks': 0.84; 'reply- to:addr:python.org': 0.84; 'subject:Using': 0.84; 'unique.': 0.84 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.0 cv=XeZXOvF5 c=1 sm=1 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=Tv4_tr9OjFAA:10 a=_wyJPbt4QFgA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=IkcTkHD0fZMA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=yBmmChjFPoYA:10 a=pGLkceISAAAA:8 a=PlafsbbOmglYWqcivh0A:9 a=QEXdDO2ut3YA:10 a=MSl-tDqOz04A:10 a=T7kr7iEPGQYxHkx8:21 a=Om4IPNn8lvJPPc32:21 a=0nF1XD0wxitMEM03M9B4ZQ==:117 X-AUTH: mrabarnett:2500 Date: Tue, 22 Jan 2013 18:49:45 +0000 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130107 Thunderbird/17.0.2 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Using filepath method to identify an .html page References: <50fe787e$0$30003$c3e8da3$5496439d@news.astraweb.com> <50fe8e69$0$30003$c3e8da3$5496439d@news.astraweb.com> <0459659d-4ec2-4c7d-bee3-b4e363c916dd@googlegroups.com> <12a22c5b-88a9-4577-a642-abe1e56cce5e@googlegroups.com> <8ad4a124-37a8-41fc-938d-9535b8affcbf@googlegroups.com> In-Reply-To: <8ad4a124-37a8-41fc-938d-9535b8affcbf@googlegroups.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: python-list@python.org 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: 61 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1358880581 news.xs4all.nl 6916 [2001:888:2000:d::a6]:59231 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:37332 On 2013-01-22 18:26, Ferrous Cranus wrote: > Τη Τρίτη, 22 Ιανουαρίου 2013 6:11:20 μ.μ. UTC+2, ο χρήστης Chris Angelico έγραψε: >> On Wed, Jan 23, 2013 at 2:59 AM, Ferrous Cranus wrote: >> >> > I just need a way to CONVERT a string(absolute path) to a 4-digit unique number with INT!!! That's all i want!! But i cannot make it work :( >> >> Either you are deliberately trolling, or you have a major >> comprehension problem. Please go back and read, carefully, all the >> remarks you've been offered in this thread. Feel free to ask for >> clarification of anything that doesn't make sense, but be sure to read >> all of it. You are asking something that is fundamentally >> impossible[1]. There simply are not enough numbers to go around. >> >> ChrisA >> >> [1] Well, impossible in decimal. If you work in base 4294967296, you >> >> could do what you want in four "digits". > > Fundamentally impossible? > Yes. > Well.... > > OK: How about this in Perl: > > $ cat testMD5.pl > use strict; > > foreach my $url(qw@ /index.html /about/time.html @){ > hashit($url); > } > > sub hashit { > my $url=shift; > my @ltrs=split(//,$url); > my $hash = 0; > > foreach my $ltr(@ltrs){ > $hash = ( $hash + ord($ltr)) %10000; > } > printf "%s: %0.4d\n",$url,$hash > > } > > > which yields: > $ perl testMD5.pl > /index.html: 1066 > /about/time.html: 1547 > That shortens the int to 4 digits. A hash isn't guaranteed to be unique. A hash is an attempt to make an int which is highly sensitive to a change in the data so that a small change in the data will result in a different int. If the change is big enough it _could_ give the same int, but the hope is that it probably won't. (Ideally, if the hash has 4 decimal digits, you'd hope that the chance of different data giving the same hash would be about 1 in 10000.)