Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!newsfeed.kamp.net!newsfeed.kamp.net!newsfeed.freenet.ag!news2.euro.net!amsnews11.chello.com!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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'args': 0.05; 'character,': 0.07; 'python': 0.08; 'alphabet': 0.09; 'dict': 0.09; 'am,': 0.12; 'thanks!': 0.14; '(eg.': 0.16; 'ideas?': 0.16; 'received:192.168.1.104': 0.16; 'set)': 0.16; 'sha1': 0.16; 'subject:independent': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.18; '>>>': 0.18; 'digest': 0.19; 'cc:no real name:2**0': 0.20; 'header:In-Reply-To:1': 0.22; 'cc:2**0': 0.24; 'command': 0.24; 'times,': 0.24; 'cc:addr:python.org': 0.29; 'pm,': 0.29; '(unless': 0.30; 'hash': 0.30; 'subject:?': 0.31; 'list': 0.32; 'sort': 0.33; 'header:User-Agent:1': 0.33; 'but': 0.37; 'received:192': 0.37; 'using': 0.38; 'first.': 0.39; 'possible.': 0.39; 'should': 0.39; 'received:192.168': 0.40; 'order': 0.62; 'header:Reply-To:1': 0.71; 'reply-to:no real name:2**0': 0.72; '08:55': 0.84 Date: Fri, 02 Dec 2011 13:39:44 -0500 From: Dave Angel User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.23) Gecko/20110922 Thunderbird/3.1.15 MIME-Version: 1.0 To: Neal Becker Subject: Re: order independent hash? References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:2nLv4Lfqsnr2FFRi1fqtJyuyk6xqcd0n11NG51ZM4y0 Ib73zaV8WyzL8yz8KlNXGIuuwQ9ySzxnf95HlMdS5a3nERHnR1 +OJKhLV1xqBCoJqjOIPdiOvaZ3AHT5f0MexAzQSntlhGttVOLq +bPptJmE/FDKMJODJ6CxsmHUmvgFbTCNsqnrqc6c9QWofSoNsl snP2JK+V8yRbXpL4KgwMiffllY8REQNDN9DlhGPtetr0a+a5NM v+6IqAf6cBqxg77VT0ihYbIelYluoVSr2HeVrScfmV6LC8ZRQZ BIvxYtvENMD3F5ck5jZxcLGt15w6cArc8M6taTufkxJyFjXgg= = Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: d@davea.name 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: 1322851211 news.xs4all.nl 6971 [2001:888:2000:d::a6]:46207 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:16566 On 12/01/2011 08:55 AM, Neal Becker wrote: > Gelonida N wrote: > >> On 11/30/2011 01:32 PM, Neal Becker wrote: >>> I like to hash a list of words (actually, the command line args of my >>> program) in such a way that different words will create different hash, but >>> not sensitive >>> to the order of the words. Any ideas? >>> >> Do youmean hash like digest like md5sum / sha1 ? >> >> >> You should sort the words alphabetically, concatenate them with a space >> or any character, that will NEVER be part of a word and calulate the hash. >> >> If words can exist multiple times, then youhad tu uniqufy them (u using >> a python dict / set) first. > Yes that sounds just like what I wanted - thanks! > "different words will create different hash, but not sensitive to the order of the words" Just note that you can only say that "probably create" a different hash. If the hash number is constrained in size (eg. 32 bits), then a collision is possible. (Unless of course you also constrain the alphabet and/or length of the words involved) -- DaveA