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


Groups > comp.lang.python > #33568

RE: Python Interview Questions

From "Prasad, Ramit" <ramit.prasad@jpmorgan.com>
Subject RE: Python Interview Questions
Date 2012-11-19 23:57 +0000
References (5 earlier) <roy-B2D5FF.12535018112012@news.panix.com> <50a97de0$0$29983$c3e8da3$5496439d@news.astraweb.com> <roy-BD53B0.21093618112012@news.panix.com> <50a9e5cf$0$21863$c3e8da3$76491128@news.astraweb.com> <roy-03667B.09591919112012@news.panix.com>
Newsgroups comp.lang.python
Message-ID <mailman.20.1353369510.29569.python-list@python.org> (permalink)

Show all headers | View raw


Roy Smith wrote:
> 
> OK, I've just read back over the whole thread.  I'm really struggling to
> understand what point you're trying to make.  I started out by saying:
> 
> > Use a list when you need an ordered collection which is mutable (i.e.
> > can be altered after being created).  Use a tuple when you need an
> > immutable list (such as for a dictionary key).
> 
> To which you obviously objected.  So now you write:
> 
> > I think a tuple is an immutable sequence of items, and a list is a
> > mutable sequence of items.
> 
> So how is that different from what I said?  Is this whole argument
> boiling down to your use of "immutable sequence" vs. my use of
> "immutable list"?


'''
Roy:
> Use a list when you need an ordered collection which is mutable (i.e.
> can be altered after being created).  Use a tuple when you need an
> immutable list (such as for a dictionary key).
Steven:
I keep hearing about this last one, but I wonder... who *actually* does 
this? I've created many, many lists over the years -- lists of names, 
lists of phone numbers, lists of directory search paths, all sorts of 
things. I've never needed to use one as a dictionary key.
'''

To me this is more of a question than an argument. Now moving
on to your specific example.

'''
def extract_stack(lines):
    "in traceback_helper module "
    header = lines[0]
    stack = []
    for line in lines:
        m = frame_pattern.match(line)
        if not m:
            continue
        frame = (m.group('path'), m.group('function'))
        stack.append(frame)
    # [Convert to tuple and return after finished building stack.]
    return (header, stack)
[...]
def main(args):
    crashes = {}
    [...]
    for line in open(log_file):
        if does_not_look_like_a_stack_dump(line):
             continue
        lines = traceback_helper.unfold(line)
        header, stack = traceback_helper.extract_stack(lines)
        signature = tuple(stack)
        if signature in crashes:
            count, header = crashes[signature]
            crashes[signature] = (count + 1, header)
        else:

            crashes[signature] = (1, header)
'''

Seems to me that Steven is suggesting that stack (after being built)
should converted to a tuple before being returned, because a "stack" 
for any unique exception should be unique and immutable. You do this
anyway; you just do it before putting it into a dictionary rather
than before returning it.

Same net effect (as long as you do not modify `stack` later), so no 
real argument.


~Ramit


This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  

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


Thread

Re: Python Interview Questions chinjannisha@gmail.com - 2012-11-17 10:01 -0800
  Re: Python Interview Questions Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-11-18 01:54 -0500
  Re: Python Interview Questions Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-18 09:39 +0000
    Re: Python Interview Questions Roy Smith <roy@panix.com> - 2012-11-18 08:53 -0500
      Re: Python Interview Questions Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-18 16:50 +0000
        Re: Python Interview Questions "D'Arcy J.M. Cain" <darcy@druid.net> - 2012-11-18 12:16 -0500
        Re: Python Interview Questions Roy Smith <roy@panix.com> - 2012-11-18 12:53 -0500
          Re: Python Interview Questions Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-19 00:31 +0000
            Re: Python Interview Questions Roy Smith <roy@panix.com> - 2012-11-18 21:09 -0500
              Re: Python Interview Questions Chris Angelico <rosuav@gmail.com> - 2012-11-19 13:18 +1100
              Re: Python Interview Questions Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-11-19 02:42 +0000
              Re: Python Interview Questions Ian Kelly <ian.g.kelly@gmail.com> - 2012-11-18 23:01 -0700
              Re: Python Interview Questions Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-19 07:54 +0000
                Re: Python Interview Questions Roy Smith <roy@panix.com> - 2012-11-19 09:30 -0500
                Re: Python Interview Questions Ian Kelly <ian.g.kelly@gmail.com> - 2012-11-19 09:44 -0700
                Re: Python Interview Questions Terry Reedy <tjreedy@udel.edu> - 2012-11-19 15:41 -0500
                Re: Python Interview Questions Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-19 23:42 +0000
                Re: Python Interview Questions Roy Smith <roy@panix.com> - 2012-11-19 21:33 -0500
                Re: Python Interview Questions Roy Smith <roy@panix.com> - 2012-11-19 09:59 -0500
                Re: Python Interview Questions Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-19 23:53 +0000
                Re: Python Interview Questions Roy Smith <roy@panix.com> - 2012-11-19 22:14 -0500
                RE: Python Interview Questions "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-11-19 23:57 +0000
              Re: Python Interview Questions Terry Reedy <tjreedy@udel.edu> - 2012-11-19 03:27 -0500
        Re: Python Interview Questions Chris Angelico <rosuav@gmail.com> - 2012-11-19 07:02 +1100

csiph-web