Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Creating a dictionary
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
arg...@gmail.com  
View profile  
 More options Oct 9 2012, 7:59 am
Newsgroups: comp.lang.python
From: arg...@gmail.com
Date: Tue, 9 Oct 2012 04:59:49 -0700 (PDT)
Local: Tues, Oct 9 2012 7:59 am
Subject: Creating a dictionary
below is the text file i have How to create Facility as a key and then assign multiple values to it

FACILITY : BACKUP
FAILED BACKUP_BEFORE
FAILED BACKUP_INTERCHANGE
Total : 34
Passed : 32
Failed : 2
Not Run : 0

FACILITY : CDU
Total : 9
Passed : 9
Failed : 0

for example Facility BACKUP is a key & its values are Total Passed, Failed Not Run and Facility CDU as a key & its values Total:9,Passed:9,Failed:0 etc...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Steven D'Aprano  
View profile  
 More options Oct 9 2012, 9:00 am
Newsgroups: comp.lang.python
From: Steven D'Aprano <steve+comp.lang.pyt...@pearwood.info>
Date: 09 Oct 2012 13:00:46 GMT
Local: Tues, Oct 9 2012 9:00 am
Subject: Re: Creating a dictionary

On Tue, 09 Oct 2012 04:59:49 -0700, argbsk wrote:
> below is the text file i have How to create Facility as a key and then
> assign multiple values to it

To use Facility as a key in a dict:

d = {}
d['Facility'] = 'ham'

Note that keys are case-sensitive, so that 'Facility', 'facility',
'FACILITY' and 'FaCiLiTy' are all different.

To have multiple values assigned to a key, use a list:

d['Facility'] = ['ham', 'spam', 'cheese', 'eggs']
d['Facility'].append('tomato')

--
Steven


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Roy Smith  
View profile  
 More options Oct 9 2012, 9:08 am
Newsgroups: comp.lang.python
From: Roy Smith <r...@panix.com>
Date: Tue, 09 Oct 2012 09:08:02 -0400
Local: Tues, Oct 9 2012 9:08 am
Subject: Re: Creating a dictionary
In article <50741ffe$0$6574$c3e8da3$54964...@news.astraweb.com>,
 Steven D'Aprano <steve+comp.lang.pyt...@pearwood.info> wrote:

I think what he really wants to end up with is a dictionary of
dictionaries:

{'BACKUP': {'Total' : 34,
         'Passed' : 32,
         'Failed' : 2,
         'Not Run' : 0
      },
 'CDU': {....}

}

Or, somewhat more work, but a richer solution, create a FacilityData
class, whose attributes are total, passed, failed, not_run, etc, and
have instances of FacilityData be the values.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ulrich Eckhardt  
View profile  
 More options Oct 9 2012, 9:15 am
Newsgroups: comp.lang.python
From: Ulrich Eckhardt <ulrich.eckha...@dominolaser.com>
Date: Tue, 09 Oct 2012 15:11:25 +0200
Local: Tues, Oct 9 2012 9:11 am
Subject: Re: Creating a dictionary
Am 09.10.2012 13:59, schrieb arg...@gmail.com:

> below is the text file i have How to create Facility as a key and then assign multiple values to it

The value part of a dict element can be any kind of object, like e.g. a
tuple, namedtuple or even a dict.

Uli


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »