Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #17854

Re: How to check for single character change in a string?

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <arnodel@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.025
X-Spam-Evidence '*H*': 0.95; '*S*': 0.00; ':-)': 0.06; 'subject:string': 0.09; 'received:209.85.214.174': 0.13; 'roy': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.18; '>>>': 0.18; 'cc:no real name:2**0': 0.20; 'asked': 0.22; 'header:In-Reply- To:1': 0.22; 'cc:2**0': 0.24; 'subject:change': 0.24; 'exercise': 0.28; 'message-id:@mail.gmail.com': 0.28; 'matches': 0.29; 'cc:addr:python.org': 0.29; 'subject:?': 0.31; 'received:209.85.214': 0.32; 'subject:How': 0.35; 'but': 0.37; 'received:google.com': 0.37; 'received:209.85': 0.38; 'version:': 0.39; 'received:209': 0.40; '2011': 0.61; 'article': 0.74; 'variation': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=XHtleCO/SCM1Qm3YAETr+WrfCNI+WYKRNRsss5SG+ig=; b=YQAAfdF+RqckXUX2tRQkOvUqBadDBeM3ltU0FJtP4k7ZH8CcekWrxXOGR6FrB8L2VU UHTLxhG1+x+G3mhM8bwgU7bZNSup/p2Jmcz1AgLipYcXNojEgF5yBiNyseqUFTBZgAuQ iG5mEt2e0tI/POiVRj/BCGEHEPQBDCkau0jUw=
MIME-Version 1.0
In-Reply-To <roy-BABC0C.11104024122011@news.panix.com>
References <th7hs8-one.ln1@chris.zbmc.eu> <roy-AAAEEA.10571424122011@news.panix.com> <roy-BABC0C.11104024122011@news.panix.com>
Date Sat, 24 Dec 2011 17:09:57 +0000
Subject Re: How to check for single character change in a string?
From Arnaud Delobelle <arnodel@gmail.com>
To Roy Smith <roy@panix.com>
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.4052.1324746600.27778.python-list@python.org> (permalink)
Lines 20
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1324746600 news.xs4all.nl 6840 [2001:888:2000:d::a6]:60470
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:17854

Show key headers only | View raw


On 24 December 2011 16:10, Roy Smith <roy@panix.com> wrote:
> In article <roy-AAAEEA.10571424122011@news.panix.com>,
>  Roy Smith <roy@panix.com> wrote:
>
>> >>> len([x for x in zip(s1, s2) if x[0] != x[1]])
>
> Heh, Ian Kelly's version:
>
>> sum(a == b for a, b in zip(str1, str2))
>
> is cleaner than mine.  Except that Ian's counts matches and the OP asked
> for non-matches, but that's an exercise for the reader :-)

Here's a variation on the same theme:

sum(map(str.__ne__, str1, str2))

-- 
Arnaud

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

How to check for single character change in a string? tinnews@isbd.co.uk - 2011-12-24 15:26 +0000
  Re: How to check for single character change in a string? Roy Smith <roy@panix.com> - 2011-12-24 10:57 -0500
    Re: How to check for single character change in a string? Roy Smith <roy@panix.com> - 2011-12-24 11:10 -0500
      Re: How to check for single character change in a string? Arnaud Delobelle <arnodel@gmail.com> - 2011-12-24 17:09 +0000
        Re: How to check for single character change in a string? Rick Johnson <rantingrickjohnson@gmail.com> - 2011-12-24 10:22 -0800
      Re: How to check for single character change in a string? tinnews@isbd.co.uk - 2011-12-26 22:37 +0000
  Re: How to check for single character change in a string? Ian Kelly <ian.g.kelly@gmail.com> - 2011-12-24 08:57 -0700

csiph-web