Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #28607
| Path | csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <ian@feete.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.004 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'f.close()': 0.07; 'filename': 0.07; 'filenames': 0.07; '"w")': 0.09; 'filenames:': 0.09; 'subject:Function': 0.09; 'extension': 0.13; 'extensions': 0.13; 'duplicates': 0.16; 'from:addr:ian': 0.16; 'guys,': 0.16; 'set()': 0.16; 'skip:" 70': 0.16; 'wrote:': 0.17; 'module': 0.19; 'skip:" 40': 0.20; 'trying': 0.21; 'import': 0.21; 'header:In- Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'ext': 0.27; 'list:': 0.27; 'received:208.97': 0.29; 'received:208.97.132': 0.29; 'received:dreamhost.com': 0.29; 'received:g.dreamhost.com': 0.29; "i'm": 0.29; 'function': 0.30; 'code': 0.31; 'etc.)': 0.32; 'print': 0.32; 'to:addr:python-list': 0.33; 'path': 0.35; 'should': 0.36; 'subject:: ': 0.38; 'files': 0.38; 'skip:o 20': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'you.': 0.61; 'containing': 0.61; 'received:208': 0.63; 'here': 0.65; 'subject:content': 0.84; 'examine': 0.95 |
| DKIM-Signature | v=1; a=rsa-sha1; c=relaxed; d=feete.org; h=message-id :date:from:mime-version:to:subject:references:in-reply-to :content-type:content-transfer-encoding; s=feete.org; bh=gkXaKMF HmkY//pDtMDj3TqREPNI=; b=b49IHvecp+JKCKl6a3+Gyvd/WfOHs8g3YiYaCEb 6y3daJYFc9KNidhbv+HOBi4fwcc212z9O5K6/aqyP+mg6y/XiSDjlaZgv6/PT4Vm FuSLsrNClbocgel8LTcHKobHbttDH5eqh/ve9trY373GF86T38gmXx/gFiue2+jt WzhI= |
| Date | Thu, 06 Sep 2012 16:06:35 +0100 |
| From | Ian Foote <ian@feete.org> |
| User-Agent | Mozilla/5.0 (X11; Linux i686; rv:15.0) Gecko/20120827 Thunderbird/15.0 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: Function for examine content of directory |
| References | <feae1d5a-c477-4e21-8136-c14e38672cb9@googlegroups.com> |
| In-Reply-To | <feae1d5a-c477-4e21-8136-c14e38672cb9@googlegroups.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| 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.307.1346944006.27098.python-list@python.org> (permalink) |
| Lines | 28 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1346944006 news.xs4all.nl 6945 [2001:888:2000:d::a6]:34936 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:28607 |
Show key headers only | View raw
On 06/09/12 15:56, Tigerstyle wrote:
> Hi guys,
>
> 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.)
>
> This is the code so far:
> --
> import os
>
> path = "v:\\workspace\\Python2_Homework03\\src\\"
> dirs = os.listdir( path )
> filenames = {"this.txt", "that.txt", "the_other.txt","this.doc","that.doc","this.pdf","first.txt","that.pdf"}
> extensions = []
Try using a set here instead of a list:
extensions = set()
> for filename in filenames:
> f = open(filename, "w")
> f.write("Some text\n")
> f.close()
> name , ext = os.path.splitext(f.name)
> extensions.append(ext)
and use:
extensions.add(ext)
This should take care of duplicates for you.
Regards,
Ian
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Function for examine content of directory Tigerstyle <laddosingh@gmail.com> - 2012-09-06 07:56 -0700
Re: Function for examine content of directory Ian Foote <ian@feete.org> - 2012-09-06 16:06 +0100
Re: Function for examine content of directory MRAB <python@mrabarnett.plus.com> - 2012-09-06 16:20 +0100
Re: Function for examine content of directory Tigerstyle <laddosingh@gmail.com> - 2012-09-06 13:26 -0700
Re: Function for examine content of directory Tigerstyle <laddosingh@gmail.com> - 2012-09-06 13:26 -0700
Re: Function for examine content of directory Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-09-06 17:26 -0400
Re: Function for examine content of directory Chris Angelico <rosuav@gmail.com> - 2012-09-07 07:48 +1000
Re: Function for examine content of directory Tigerstyle <laddosingh@gmail.com> - 2012-09-07 07:23 -0700
Re: Function for examine content of directory Tigerstyle <laddosingh@gmail.com> - 2012-09-07 07:28 -0700
Re: Function for examine content of directory Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-09-07 15:21 -0400
csiph-web