Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.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.022 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'python': 0.09; 'sep': 0.09; 'subject:Function': 0.09; 'type;': 0.09; 'extension': 0.13; 'already,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'wrote:': 0.17; 'module': 0.19; 'sort': 0.21; 'trying': 0.21; 'received:209.85.214.174': 0.21; "haven't": 0.23; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'message- id:@mail.gmail.com': 0.27; "i'm": 0.29; 'fri,': 0.30; 'function': 0.30; 'etc.)': 0.32; 'print': 0.32; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'received:209.85': 0.35; 'received:209': 0.37; 'subject:: ': 0.38; 'files': 0.38; 'easier': 0.38; 'to:addr:python.org': 0.39; 'received:209.85.214': 0.39; 'header:Received:5': 0.40; 'containing': 0.61; 'map': 0.61; 'directly.': 0.78; 'subject:content': 0.84; 'examine': 0.95 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=ppg1yoNaCGCRQ66rMgB8uTpxvwo1lAE8EJamPLVsQKU=; b=lmsnCrObD/iiEDJt5KxNV6qXEnS13bZ4bic+V/42KIU+FPSoiHJw454Lx4OUD/Mdc0 EpJht7Ep1U/DnV4Ji6X91hJMMI/uWh36H2Wuj0c5Zv8XIvPUckvUyBVnzP+Zmbva3gBh slrc1fkK0sPyuQ7+VZcmZsvj4Oxe3eEal1yHJ6UYKlFNKpWhQOTA5Evo3KeqbEJT593n YmH3Ha6WiM2ZdXH+MFLznYFmawZ6d9+ovVRyahTJ9vfUs5okVrzgb9IASdQNkHxwzznj sUWeQAnP9Q5F49Tf8qxCDpLN6xggyBEc+ezWThzQqCznXvgprMtlsWwnO3rnGZyDJe32 aCOg== MIME-Version: 1.0 In-Reply-To: References: Date: Fri, 7 Sep 2012 07:48:27 +1000 Subject: Re: Function for examine content of directory From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 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: 8 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1346968110 news.xs4all.nl 6966 [2001:888:2000:d::a6]:60534 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:28646 On Fri, Sep 7, 2012 at 12:56 AM, Tigerstyle wrote: > I'm trying to write a module containing a function to examine the contents of the current working directory and print out a count of how many files have each extension (".txt", ".doc", etc.) If you haven't already, look into the Python 'dict' type; you may find it easier to work with for this sort of job. You can map an extension ("txt") to its count (4) directly. ChrisA