From owner-freebsd-questions@FreeBSD.ORG Wed Aug 20 17:23:05 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 71B241065686 for ; Wed, 20 Aug 2008 17:23:05 +0000 (UTC) (envelope-from cswiger@mac.com) Received: from asmtpout015.mac.com (asmtpout015.mac.com [17.148.16.90]) by mx1.freebsd.org (Postfix) with ESMTP id 5EC8A8FC24 for ; Wed, 20 Aug 2008 17:23:05 +0000 (UTC) (envelope-from cswiger@mac.com) MIME-version: 1.0 Content-transfer-encoding: 7BIT Content-type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Received: from cswiger1.apple.com ([17.227.140.124]) by asmtp015.mac.com (Sun Java(tm) System Messaging Server 6.3-7.03 (built Aug 7 2008; 32bit)) with ESMTPSA id <0K5W003WWTLZDN10@asmtp015.mac.com> for freebsd-questions@freebsd.org; Wed, 20 Aug 2008 10:22:48 -0700 (PDT) Message-id: <33B2B005-C7DC-46A2-8C75-E7781710B26D@mac.com> From: Chuck Swiger To: Andrew Gould In-reply-to: Date: Wed, 20 Aug 2008 10:22:46 -0700 References: X-Mailer: Apple Mail (2.928.1) Cc: FreeBSD Questions Mailing List Subject: Re: Python script for configuring wifi hot spots on FreeBSD X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 Aug 2008 17:23:05 -0000 Hi, Andrew-- On Aug 20, 2008, at 8:44 AM, Andrew Gould wrote: > 2. I store data in Python dictionaries. When I display the > dictionaries, > the numbered options are not in order and I can't > figure out how to sort them. This appears to be a cosmetic issue > only; > but it still bothers me. If you have a bunch of keys that are sortable, you can do something like: >>> dict = { 1: 'alpha', 4: 'gamma', 2: 'beta', 3: 'delta' } >>> keylist = dict.keys(); keylist.sort() >>> for k in keylist: print k, dict[k] ... 1 alpha 2 beta 3 delta 4 gamma See http://docs.python.org/lib/typesmapping.html for more details: (3) Keys and values are listed in an arbitrary order which is non- random, varies across Python implementations, and depends on the dictionary's history of insertions and deletions. If items(), keys(), values(), iteritems(), iterkeys(), and itervalues() are called with no intervening modifications to the dictionary, the lists will directly correspond. This allows the creation of (value, key) pairs using zip(): "pairs = zip(a.values(), a.keys())". The same relationship holds for the iterkeys() and itervalues() methods: "pairs = zip(a.itervalues(), a.iterkeys())" provides the same value for pairs. Another way to create the same list is "pairs = [(v, k) for (k, v) in a.iteritems()]". > 3. My knowledge of networking is at a basic level. > > I have attached the script -- it is only 4KB. The mailing list strips off many file attachments. You'd do better to put your script on a website somewhere, and mail out the URL to it... Regards, -- -Chuck