Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.85.MISMATCH!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'exception': 0.03; 'argument': 0.04; 'subject:Python': 0.05; 'modify': 0.05; 'things.': 0.05; 'completeness': 0.07; 'key.': 0.07; "'''": 0.09; '(1,': 0.09; 'immutable': 0.09; 'lines:': 0.09; 'mutable': 0.09; 'received:155': 0.09; 'tuple': 0.09; 'def': 0.10; 'finished': 0.15; 'stack': 0.15; 'altered': 0.16; 'argument.': 0.16; 'count,': 0.16; 'crashes': 0.16; 'disclaimers': 0.16; 'disclaimers,': 0.16; 'from:addr:jpmorgan.com': 0.16; 'received:155.180': 0.16; 'received:155.180.234': 0.16; 'received:155.180.234.122': 0.16; 'received:159.53': 0.16; 'received:bankone.net': 0.16; 'received:exchad.jpmchase.net': 0.16; 'received:jpmchase.com': 0.16; 'received:jpmchase.net': 0.16; 'received:se3.svr.bankone.net': 0.16; 'received:svr.bankone.net': 0.16; 'returned,': 0.16; 'roy': 0.16; 'securities,': 0.16; 'sorts': 0.16; 'stack)': 0.16; 'suggesting': 0.16; 'thread.': 0.16; 'url:disclosures': 0.16; 'url:jpmorgan': 0.16; 'wrote:': 0.17; 'example.': 0.17; 'items.': 0.17; 'obviously': 0.18; 'module': 0.19; 'putting': 0.20; 'to:name:python-list@python.org': 0.20; 'trying': 0.21; 'converted': 0.22; 'subject:Questions': 0.22; 'to:2**1': 0.23; "i've": 0.23; 'seems': 0.23; 'received:169.254': 0.24; 'header': 0.24; 'header:In-Reply-To:1': 0.25; 'question': 0.27; '(as': 0.27; '(such': 0.27; 'accuracy': 0.27; 'lines': 0.28; 'this?': 0.28; '"in': 0.29; 'dictionary': 0.29; 'header,': 0.29; 'steven': 0.29; 'received:169': 0.29; "i'm": 0.29; 'header:Received:8': 0.30; 'lists': 0.31; 'point': 0.31; 'ordered': 0.33; 'to:addr:python-list': 0.33; 'list': 0.35; 'needed': 0.35; 'returning': 0.35; 'sequence': 0.35; 'continue': 0.35; 'really': 0.36; 'created': 0.36; 'but': 0.36; '(i.e.': 0.36; 'should': 0.36; 'charset:us-ascii': 0.36; 'ok,': 0.37; 'one,': 0.37; 'signature': 0.37; 'does': 0.37; 'being': 0.37; 'rather': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'think': 0.40; 'your': 0.60; 'real': 0.61; 'hearing': 0.61; 'back': 0.62; 'different': 0.63; 'information,': 0.63; 'url:email': 0.63; 'more': 0.63; 'legal': 0.65; 'subject': 0.66; 'purchase': 0.67; 'phone': 0.68; 'smith': 0.71; 'sale': 0.76; 'received:169.254.8': 0.84; 'saying:': 0.84; 'subject:Interview': 0.84; 'items,': 0.91; 'write:': 0.91; 'many,': 0.93 X-DKIM: OpenDKIM Filter v2.1.3 sz1.jpmchase.com qAJNwRtd012437 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpmorgan.com; s=smtpout; t=1353369507; bh=GoaYhfo6gzOoKPYReesi67kEra0tL76qWldQdh7IGGc=; h=From:To:Subject:Date:Message-ID:References:In-Reply-To: Content-Transfer-Encoding:MIME-Version:Content-Type; b=gxbCv1eqkv9dD4NhzldlpC1sf6PChD2Jhf76ZeY9r2u8ZCMYSh2I38PAJOMTzZW7M 2m9j7XSAe6ezsRUHrIc7NyA+f/O37riX1Vrq2/alM1u6cFp3cP9ybJyvHSqu3MSqH9 iI6Kqa86ecqiEUenBK32HjbG2xn+KnDlqpVuwTjg= From: "Prasad, Ramit" To: Roy Smith , "python-list@python.org" Subject: RE: Python Interview Questions Thread-Topic: Python Interview Questions Thread-Index: AQHNxmZzpYQlLxpYg0GWQxx92IFaPpfxwynQ Date: Mon, 19 Nov 2012 23:57:43 +0000 References: <1193768041.349129.26350@v3g2000hsg.googlegroups.com> <55443eb7-847c-4f4c-8d04-1e6b507aac00@googlegroups.com> <50a8acdc$0$29978$c3e8da3$5496439d@news.astraweb.com> <50a911ec$0$29978$c3e8da3$5496439d@news.astraweb.com> <50a97de0$0$29983$c3e8da3$5496439d@news.astraweb.com> <50a9e5cf$0$21863$c3e8da3$76491128@news.astraweb.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.67.79.47] Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-DLP-FWD: Yes Content-Type: text/plain; charset="us-ascii" 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: 45 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1353369510 news.xs4all.nl 6910 [2001:888:2000:d::a6]:59131 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:33568 Roy Smith wrote:=0D=0A> =0D=0A> OK, I've just read back over the whole thre= ad=2E I'm really struggling to=0D=0A> understand what point you're trying = to make=2E I started out by saying:=0D=0A> =0D=0A> > Use a list when you n= eed an ordered collection which is mutable (i=2Ee=2E=0D=0A> > can be altere= d after being created)=2E Use a tuple when you need an=0D=0A> > immutable = list (such as for a dictionary key)=2E=0D=0A> =0D=0A> To which you obviousl= y objected=2E So now you write:=0D=0A> =0D=0A> > I think a tuple is an imm= utable sequence of items, and a list is a=0D=0A> > mutable sequence of item= s=2E=0D=0A> =0D=0A> So how is that different from what I said? Is this who= le argument=0D=0A> boiling down to your use of "immutable sequence" vs=2E m= y use of=0D=0A> "immutable list"?=0D=0A=0D=0A=0D=0A'''=0D=0ARoy:=0D=0A> Use= a list when you need an ordered collection which is mutable (i=2Ee=2E=0D= =0A> can be altered after being created)=2E Use a tuple when you need an= =0D=0A> immutable list (such as for a dictionary key)=2E=0D=0ASteven:=0D=0A= I keep hearing about this last one, but I wonder=2E=2E=2E who *actually* do= es =0D=0Athis? I've created many, many lists over the years -- lists of nam= es, =0D=0Alists of phone numbers, lists of directory search paths, all sort= s of =0D=0Athings=2E I've never needed to use one as a dictionary key=2E=0D= =0A'''=0D=0A=0D=0ATo me this is more of a question than an argument=2E Now = moving=0D=0Aon to your specific example=2E=0D=0A=0D=0A'''=0D=0Adef extract_= stack(lines):=0D=0A "in traceback_helper module "=0D=0A header =3D li= nes[0]=0D=0A stack =3D []=0D=0A for line in lines:=0D=0A m =3D= frame_pattern=2Ematch(line)=0D=0A if not m:=0D=0A contin= ue=0D=0A frame =3D (m=2Egroup('path'), m=2Egroup('function'))=0D=0A = stack=2Eappend(frame)=0D=0A # [Convert to tuple and return after = finished building stack=2E]=0D=0A return (header, stack)=0D=0A[=2E=2E=2E= ]=0D=0Adef main(args):=0D=0A crashes =3D {}=0D=0A [=2E=2E=2E]=0D=0A = for line in open(log_file):=0D=0A if does_not_look_like_a_stack_du= mp(line):=0D=0A continue=0D=0A lines =3D traceback_helpe= r=2Eunfold(line)=0D=0A header, stack =3D traceback_helper=2Eextract_= stack(lines)=0D=0A signature =3D tuple(stack)=0D=0A if signat= ure in crashes:=0D=0A count, header =3D crashes[signature]=0D=0A= crashes[signature] =3D (count + 1, header)=0D=0A else:= =0D=0A=0D=0A crashes[signature] =3D (1, header)=0D=0A'''=0D=0A= =0D=0ASeems to me that Steven is suggesting that stack (after being built)= =0D=0Ashould converted to a tuple before being returned, because a "stack" = =0D=0Afor any unique exception should be unique and immutable=2E You do thi= s=0D=0Aanyway; you just do it before putting it into a dictionary rather=0D= =0Athan before returning it=2E=0D=0A=0D=0ASame net effect (as long as you d= o not modify `stack` later), so no =0D=0Areal argument=2E=0D=0A=0D=0A=0D=0A= ~Ramit=0D=0A=0D=0A=0D=0AThis email is confidential and subject to important= disclaimers and=0D=0Aconditions including on offers for the purchase or sa= le of=0D=0Asecurities, accuracy and completeness of information, viruses,= =0D=0Aconfidentiality, legal privilege, and legal entity disclaimers,=0D=0A= available at http://www=2Ejpmorgan=2Ecom/pages/disclosures/email=2E