Re: [Tutor] dictionaries are same but returning false

2017-07-05 Thread Peter Otten
Ashfaq wrote: > Hi Peter, > The way you find the issue is really cool! Very cool! :) Thanks ;) Here's a bonus solution: >>> import unittest >>> class T(unittest.TestCase): ... def test_xy(self): ... self.maxDiff = None ... self.assertEqual(x, y) ... >>> unittest.main() F ==

Re: [Tutor] dictionaries are same but returning false

2017-07-05 Thread shubham goyal
On Jul 5, 2017 11:09 PM, "shubham goyal" wrote: > Yha that's very smart. Only experience can drive you this way. Otherwise I > was checking value by value. > > On Jul 5, 2017 10:21 PM, "Ashfaq" wrote: > > Hi Peter, > The way you find the issue is really cool! Very cool! :) > > On Wed, Jul 5, 201

Re: [Tutor] dictionaries are same but returning false

2017-07-05 Thread Danny Yoo
The difflib library (https://docs.python.org/2/library/difflib.html) can also help with some exploratory discovery of the problem. Here's an example: >>> import difflib >>> for line in difflib.context_diff(repr(x).split(','), repr(y).split(','

Re: [Tutor] dictionaries are same but returning false

2017-07-05 Thread Mats Wichmann
On 07/05/2017 11:09 AM, Marc Tompkins wrote: > On Wed, Jul 5, 2017 at 9:51 AM, Ashfaq wrote: > >> Hi Peter, >> The way you find the issue is really cool! Very cool! :) >> >> > I agree - that is very cool. But I have also made this sort of mistake a > few times, and found it by using a very quick

Re: [Tutor] dictionaries are same but returning false

2017-07-05 Thread Marc Tompkins
On Wed, Jul 5, 2017 at 9:51 AM, Ashfaq wrote: > Hi Peter, > The way you find the issue is really cool! Very cool! :) > > I agree - that is very cool. But I have also made this sort of mistake a few times, and found it by using a very quick, low-tech method... "Unfold" the lines of the two dictio

Re: [Tutor] dictionaries are same but returning false

2017-07-05 Thread Ashfaq
Hi Peter, The way you find the issue is really cool! Very cool! :) On Wed, Jul 5, 2017 at 6:10 PM, shubham goyal wrote: > Thank you Peter. > Silly mistakes 😀 > > On Jul 5, 2017 5:10 PM, "Peter Otten" <__pete...@web.de> wrote: > > > shubham goyal wrote: > > > > > null=None > > > x={'_udp_options'

Re: [Tutor] dictionaries are same but returning false

2017-07-05 Thread shubham goyal
Thank you Peter. Silly mistakes 😀 On Jul 5, 2017 5:10 PM, "Peter Otten" <__pete...@web.de> wrote: > shubham goyal wrote: > > > null=None > > x={'_udp_options': None, '_icmp_options': None, 'attribute_map': > > {'icmp_options': 'icmpOptions', 'protocol': 'protocol', 'source': > > {'source', > > 't

Re: [Tutor] dictionaries are same but returning false

2017-07-05 Thread Peter Otten
shubham goyal wrote: > null=None > x={'_udp_options': None, '_icmp_options': None, 'attribute_map': > {'icmp_options': 'icmpOptions', 'protocol': 'protocol', 'source': > {'source', > 'tcp_options': 'tcpOptions', 'is_stateless': 'isStateless', 'udp_options': > 'udpOptions'}, '_is_stateless': False,

[Tutor] dictionaries are same but returning false

2017-07-05 Thread shubham goyal
null=None x={'_udp_options': None, '_icmp_options': None, 'attribute_map': {'icmp_options': 'icmpOptions', 'protocol': 'protocol', 'source': 'source', 'tcp_options': 'tcpOptions', 'is_stateless': 'isStateless', 'udp_options': 'udpOptions'}, '_is_stateless': False, 'swagger_types': {'icmp_options':

Re: [Tutor] Dictionaries and multiple keys/values

2013-03-26 Thread David Rock
* Robert Sjoblom [2013-03-26 05:36]: > > brittle. However, even if I was happy with that, I can't figure out > what to do in the situation where: > data[i+3] = 'Canadian, Pub Food' #should be two items, is currently a string. > My problem is that I'm... stupid. I can split the entry into a list >

Re: [Tutor] Dictionaries and multiple keys/values

2013-03-26 Thread Alan Gauld
On 26/03/13 04:36, Robert Sjoblom wrote: Georgie Porgie 87% $$$ Canadian, Pub Food So a 5 line pattern with 4 data fields. The last one containing multiple comma separated values, potentially. The three dictionaries are: name_to_rating = {} price_to_names = {'$': [], '$$': [], '$$$': [],

Re: [Tutor] Dictionaries and multiple keys/values

2013-03-26 Thread Dave Angel
On 03/26/2013 12:36 AM, Robert Sjoblom wrote: Hi again, Tutor List. I am trying to figure out a problem I've run into. Let me first say that this is an assignment, so please don't give me any answers, but just nudge me in the general direction. So the task is this: from a text file, populate thr

Re: [Tutor] Dictionaries and multiple keys/values

2013-03-25 Thread Jos Kerc
Hi, On Tue, Mar 26, 2013 at 5:36 AM, Robert Sjoblom wrote: > Hi again, Tutor List. > > I am trying to figure out a problem I've run into. Let me first say > that this is an assignment, so please don't give me any answers, but > just nudge me in the general direction. So the task is this: from a

[Tutor] Dictionaries and multiple keys/values

2013-03-25 Thread Robert Sjoblom
Hi again, Tutor List. I am trying to figure out a problem I've run into. Let me first say that this is an assignment, so please don't give me any answers, but just nudge me in the general direction. So the task is this: from a text file, populate three different dictionaries with various informati

Re: [Tutor] Dictionaries

2012-06-18 Thread Prasad, Ramit
> This sounds a wee bit like a homework assignment and we have a policy of > not doing those for you... Just to clarify, we will help you on it but not do it for you. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713

Re: [Tutor] Dictionaries

2012-06-17 Thread Alan Gauld
On 17/06/12 15:14, Selby Rowley-Cannon wrote: I am having a problem with a small application I am writing. I have to have the user input the key, then have the program output the value associated with it. A way to inform the user that the key they entered is not in the dictionary or somefing

Re: [Tutor] Dictionaries

2012-06-17 Thread Martin A. Brown
Greetings, : I am having a problem with a small application I am writing. I : have to have the user input the key, then have the program output : the value associated with it. A way to inform the user that the : key they entered is not in the dictionary or somefing would be : nice also.

Re: [Tutor] Dictionaries

2012-06-17 Thread Emile van Sebille
On 6/17/2012 7:14 AM Selby Rowley-Cannon said... Hello, I am having a problem with a small application I am writing. I have to have the user input the key, then have the program output the value associated with it. A way to inform the user that the key they entered is not in the dictionary or som

[Tutor] Dictionaries

2012-06-17 Thread Selby Rowley-Cannon
Hello,             I am having a problem with a small application I am writing. I have to have the user input the key, then have the program output the value associated with it. A way to inform the user that the key they entered is not in the dictionary or somefing would be nice also. Fank you

Re: [Tutor] Dictionaries

2012-02-10 Thread Mark Lawrence
On 10/02/2012 14:13, myles broomes wrote: Ive been given a challenge in the book im learning Python from and its basically create a program with a dictionary of father - son pairs and allow the user to add, replace and delete pairs. Ive done that without any problems but ive been giving anoth

Re: [Tutor] Dictionaries

2012-02-10 Thread Walter Prins
Hi Myles, On 10 February 2012 14:13, myles broomes wrote: > Ive been given a challenge in the book im learning Python from and its > basically create a program with a dictionary of father - son pairs and allow > the user to add, replace and delete pairs. Ive done that without any > problems but i

Re: [Tutor] Dictionaries

2012-02-10 Thread Dave Angel
On 02/10/2012 09:13 AM, myles broomes wrote: Ive been given a challenge in the book im learning Python from and its basically create a program with a dictionary of father - son pairs and allow the user to add, replace and delete pairs. Ive done that without any problems but ive been giving ano

Re: [Tutor] Dictionaries

2012-02-10 Thread Sarma Tangirala
On 10 Feb 2012 19:45, "myles broomes" wrote: > > Ive been given a challenge in the book im learning Python from and its basically create a program with a dictionary of father - son pairs and allow the user to add, replace and delete pairs. Ive done that without any problems but ive been giving ano

[Tutor] Dictionaries

2012-02-10 Thread myles broomes
Ive been given a challenge in the book im learning Python from and its basically create a program with a dictionary of father - son pairs and allow the user to add, replace and delete pairs. Ive done that without any problems but ive been giving another challenge where I have to improve the pre

Re: [Tutor] Dictionaries - Using 1 Key:Value to find another

2010-12-11 Thread Al Stern
print ("\nSorry.", grandfather, "is not a grandfather. Try again.") Thanks all. _   www.electronsbaseball.com -Original Message- From: David [mailto:bouncingc...@gmail.com] Sent: Saturday, December 11, 2010 6:35 PM To: Al Stern Cc: tutor@

Re: [Tutor] Dictionaries - Using 1 Key:Value to find another

2010-12-11 Thread David
On 12 December 2010 11:10, Al Stern wrote: > > I thought father got defined in the > > father == pairs[grandfather] > line. I have tried it a couple different ways but always get the father is > not defined error once I enter the name. I only glanced at your code, but maybe you have some typos t

Re: [Tutor] Dictionaries - Using 1 Key:Value to find another

2010-12-11 Thread col speed
On 12 December 2010 07:10, Al Stern wrote: > This was another execise in my book. Following is my code for a program > that uses dictionaries to find and edit pairs of fathers and sons. The > program works right up to the final step which is to find out if any given > father is actually a grand

[Tutor] Dictionaries - Using 1 Key:Value to find another

2010-12-11 Thread Al Stern
This was another execise in my book. Following is my code for a program that uses dictionaries to find and edit pairs of fathers and sons. The program works right up to the final step which is to find out if any given father is actually a grandfather to someone else in the dictionary. I set up m

Re: [Tutor] dictionaries help

2009-07-24 Thread Kent Johnson
On Fri, Jul 24, 2009 at 3:01 AM, wrote: >> If ws_industry contains 25 items, it will probably be faster to search >> it if it is a set rather than a list. Just use >> ws_industry = set(('it', 'science')) > > ws_industry contains only unique values OK. It will still be faster to check membership i

Re: [Tutor] dictionaries help

2009-07-24 Thread davidwilson
Hello Original Message From: Kent Johnson Apparently from: kent3...@gmail.com To: davidwil...@safe-mail.net Cc: tutor@python.org Subject: Re: [Tutor] dictionaries help Date: Thu, 23 Jul 2009 21:44:33 -0400 > On Thu, Jul 23, 2009 at 7:09 PM, wrote: > > Hello again, &g

Re: [Tutor] dictionaries help

2009-07-23 Thread Kent Johnson
On Thu, Jul 23, 2009 at 7:09 PM, wrote: > Hello again, > Here is my full attempt, can you please tell me if it is OK and if there > should be any improvements >     ws_industry = ('it', 'science') code = ws_industry[0] active = [] industries = [{'code': 'it', 'name': 'Informat

Re: [Tutor] dictionaries help

2009-07-23 Thread davidwilson
more efficient. Basically I have a big list of industries and I want to verify for each member whether they are active or not active. The industry list of dictionaries will stay fixed at about 25 items, whereas the ws_industry tuple will change depending. I have to go through about 20,000 item

Re: [Tutor] dictionaries help

2009-07-23 Thread davidwilson
thank you for all your answers Original Message From: Norman Khine Apparently from: tutor-bounces+davidwilson=safe-mail@python.org To: tutor@python.org Subject: Re: [Tutor] dictionaries help Date: Thu, 23 Jul 2009 21:59:01 +0100 > Also you can use list comprehens

Re: [Tutor] dictionaries help

2009-07-23 Thread Norman Khine
Also you can use list comprehension In [1]: my_lst = [{'code': 'aaa', 'name': 'a name'}, {'code': 'bbb', 'name': 'b name'}] In [2]: my_code = 'aaa' In [3]: print [d for d in my_lst if d['code'] == my_code] --> print([d for d in my_lst if d['code'] == my_code]) [{'code': 'aaa', 'name': 'a nam

Re: [Tutor] dictionaries help

2009-07-23 Thread Alan Gauld
"Alan Gauld" wrote Oops! Should be: def findDict(value, dictList): for dct in dictList: if dct.get('code', '') == my_code if dct.get('code', '') == value return dct HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___

Re: [Tutor] dictionaries help

2009-07-23 Thread Alan Gauld
wrote i would like to understand how dictionaries work. They work like a lookup table. You provide a key and lookup the corresponding value in the dictionary. So to implement a traditional language dictionary the keys would be words and the values would be a list of definitions. You read th

Re: [Tutor] dictionaries help

2009-07-23 Thread vince spicer
this should work def find_value(value, lst): for obj in lst: if value in obj.values(): return obj >> find_value("aaa", my_lst) Vince On Thu, Jul 23, 2009 at 9:55 AM, wrote: > hello, > please excuse me, but i would like to understand how dictionaris work. > > for examp

[Tutor] dictionaries help

2009-07-23 Thread davidwilson
hello, please excuse me, but i would like to understand how dictionaris work. for example: >>> my_lst = [{'code': 'aaa', 'name': 'a name'}, {'code': 'bbb', 'name': 'b >>> name'}] >>> my_code = 'aaa' from the above i would like to compare my_code and return the dictionary which has code == my_c

Re: [Tutor] Dictionaries or Numpy?

2008-05-17 Thread Adam Clarridge
On 5/16/08, John Fouhy <[EMAIL PROTECTED]> wrote: > > On 17/05/2008, Adam Clarridge <[EMAIL PROTECTED]> wrote: > > I'm fairly new to Python, and I am not sure whether it would be faster > > for me to use a Dictionary data type to represent the board > > (advantages: indices can be strings or tup

Re: [Tutor] Dictionaries or Numpy?

2008-05-16 Thread John Fouhy
On 17/05/2008, Adam Clarridge <[EMAIL PROTECTED]> wrote: > I'm fairly new to Python, and I am not sure whether it would be faster > for me to use a Dictionary data type to represent the board > (advantages: indices can be strings or tuples, and the dictionary can > store different types of data

[Tutor] Dictionaries or Numpy?

2008-05-16 Thread Adam Clarridge
Hi, I'm writing an AI for a board game called Blokus, and I believe that the quality of the program is going to greatly depend on the efficiency of the algorithm I use to generate legal moves and rate them. I know sort of how I'm going to do this legal move generation, and I know it is going to re

Re: [Tutor] dictionaries, objects and scoping...

2008-01-22 Thread Tiger12506
Just a thought~ The built-in id() function can be useful in helping to sort out stuff. Returns a unique identifier for each object created so you can test whether a different name is a different object or just a different name for the same object. (This is what the 'is' operator does... Note:

Re: [Tutor] dictionaries, objects and scoping...

2008-01-22 Thread Alan Gauld
"John Morris" <[EMAIL PROTECTED]> wrote > So this seems like it will make scope/namespaces a bit > interesting... namespaces in python are literally that, they are spaces where *names* are visible. Objects are something else entirely and assignment only pins a name to an object. So in Python na

Re: [Tutor] dictionaries, objects and scoping...

2008-01-21 Thread John Morris
Thanks. I think this is understood better now. Thanks to everyone for their help. I was running low on ways to express this for clearer understanding. Awesomeness once again from [EMAIL PROTECTED] - John On Jan 21, 2008 10:18 PM, Kent Johnson <[EMAIL PROTECTED]> wrote: > John Morris wrote: > >

Re: [Tutor] dictionaries, objects and scoping...

2008-01-21 Thread Kent Johnson
John Morris wrote: > Ahhh. so namespaces are scoped, not objects... I would say names are scoped, but I guess namespaces are too. > You have to keep your objects separate (and make copies when needed), Yes > Python just keeps namespaces (names that refer to an object) scoped > according to it

Re: [Tutor] dictionaries, objects and scoping...

2008-01-21 Thread John Fouhy
On 22/01/2008, John Morris <[EMAIL PROTECTED]> wrote: > So if you create an object way up in terms of scope (global), then all > python does is handle what names are available in a given scope to refer to > it. If you want a separate object you have to take care of that yourself. > Efficient. Massi

Re: [Tutor] dictionaries, objects and scoping...

2008-01-21 Thread John Morris
Ahhh. so namespaces are scoped, not objects... You have to keep your objects separate (and make copies when needed), Python just keeps namespaces (names that refer to an object) scoped according to it's rules: http://docs.python.org/ref/naming.html So if you create an object way up in terms of sco

Re: [Tutor] dictionaries, objects and scoping...

2008-01-21 Thread Kent Johnson
John Morris wrote: > Thanks, > > so I could/should do > > self.ot = Bar(self.name.copy()) instead Yes, if you want a copy you have to ask for it. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] dictionaries, objects and scoping...

2008-01-21 Thread John Morris
So this seems like it will make scope/namespaces a bit interesting... Any good references on why this is this way? I.e., why assignment passes across scopes instead of copy. Or is it just explicit versus implicit? On Jan 21, 2008 9:32 PM, John Fouhy <[EMAIL PROTECTED]> wrote: > On 22/01/2008,

Re: [Tutor] dictionaries, objects and scoping...

2008-01-21 Thread Kent Johnson
John Morris wrote: > Does it have something to do with: > http://effbot.org/pyfaq/why-are-default-values-shared-between-objects.htm > > And if so can anyone explain it a bit for me, I'm being slow tonight. > > I thought each class got it's own namespace and this sharing of mutable > objects is c

Re: [Tutor] dictionaries, objects and scoping...

2008-01-21 Thread John Fouhy
On 22/01/2008, John Morris <[EMAIL PROTECTED]> wrote: > I thought each class got it's own namespace and this sharing of mutable > objects is confusing me. Each class gets its own namespace, but names are different from objects. For example: >>> x = [1, 2, 3] >>> y = x >>> y.append(4) >>> x [1, 2

Re: [Tutor] dictionaries, objects and scoping...

2008-01-21 Thread John Morris
Thanks, so I could/should do self.ot = Bar(self.name.copy()) instead On Jan 21, 2008 9:25 PM, Kent Johnson <[EMAIL PROTECTED]> wrote: > John Morris wrote: > > > Why does the pop in the Bar class nuke the srv k & v from Foo.name > > as well? > > Because they are both names for

Re: [Tutor] dictionaries, objects and scoping...

2008-01-21 Thread John Morris
Does it have something to do with: http://effbot.org/pyfaq/why-are-default-values-shared-between-objects.htm And if so can anyone explain it a bit for me, I'm being slow tonight. I thought each class got it's own namespace and this sharing of mutable objects is confusing me. Thanks. On Jan 21,

Re: [Tutor] dictionaries, objects and scoping...

2008-01-21 Thread Kent Johnson
John Morris wrote: > Why does the pop in the Bar class nuke the srv k & v from Foo.name > as well? Because they are both names for the same dict. Assignment in Python does not copy values; it binds a name to a value. Some good references: http://effbot.org/zone/python-objects

[Tutor] dictionaries, objects and scoping...

2008-01-21 Thread John Morris
class Foo: '''Represents a foo''' def __init__(self, name): '''Initializes the person's data''' self.name = name print '(Initializing %s)' % self.name self.ot = Bar(self.name) print '(After Other - %s)' % self.name class Bar: def __init__(self, name): self.name

Re: [Tutor] dictionaries and memory handling

2007-03-03 Thread Andrei
> But most of my dictionaries are nested, and since both keys and values > in the dbm 'dictionaries' have to be strings, I can't immediately see > how I could get it to work. > > A bit more detail: I deal with conditional probabilities, with up to 4 > parameters. These parameters are numbers or

Re: [Tutor] dictionaries and memory handling

2007-02-26 Thread Arild B. Næss
februar 2007 18.30.40 GMT+01:00 Til: tutor@python.org Emne: [Tutor] dictionaries and memory handling Delivered-To: [EMAIL PROTECTED] Hi, I'm working on a python script for a task in statistical language processing. Briefly put it all boils down to counting different things in very large text

Re: [Tutor] dictionaries and memory handling

2007-02-26 Thread Arild B. Næss
februar 2007 18.30.40 GMT+01:00 Til: tutor@python.org Emne: [Tutor] dictionaries and memory handling Delivered-To: [EMAIL PROTECTED] Hi, I'm working on a python script for a task in statistical language processing. Briefly put it all boils down to counting different things in very large text

Re: [Tutor] dictionaries and memory handling

2007-02-24 Thread Kent Johnson
Arild B. Næss wrote: > Hi, > > I'm working on a python script for a task in statistical language > processing. Briefly put it all boils down to counting different > things in very large text files, doing simple computations on these > counts and storing the results. I have been using pytho

Re: [Tutor] Dictionaries of Tuples of Strings

2007-02-23 Thread Bill Sconce
On Fri, 23 Feb 2007 13:45:54 -0800 (PST) Terry Carroll <[EMAIL PROTECTED]> wrote: > > Any other way to create an empty tuple? > > Answering my own question: > > >>> t=() > >>> type(t) > Giving the lie to my earlier summary (that tuples are indicated by commas only -- arrgh :) __

Re: [Tutor] Dictionaries of Tuples of Strings

2007-02-23 Thread Luke Paireepinart
Terry Carroll wrote: > On Fri, 23 Feb 2007, Luke Paireepinart wrote: > > >> That's because you can't make tuples of single values. >> Think of it like this: >> a TUple needs TWO elements or more. >> > > No, a tuple can also be of one element, or even none. You can create a > single-element

Re: [Tutor] Dictionaries of Tuples of Strings

2007-02-23 Thread Terry Carroll
On Fri, 23 Feb 2007, Terry Carroll wrote: > You can also create an empty tuple, but I think only through the tuple() > method: > >>> t=tuple() > > Any other way to create an empty tuple? Answering my own question: >>> t=() >>> type(t) ___ Tutor m

Re: [Tutor] Dictionaries of Tuples of Strings

2007-02-23 Thread Terry Carroll
On Fri, 23 Feb 2007, Bill Sconce wrote: > It's not true that >parentheses indicate tuples > (They don't. Not unless there are "commas in there".) Except in one case, the empty tuple: t = () ___ Tutor maillist - Tutor@python.org http://mail.pyt

Re: [Tutor] Dictionaries of Tuples of Strings

2007-02-23 Thread Terry Carroll
On Fri, 23 Feb 2007, Luke Paireepinart wrote: > That's because you can't make tuples of single values. > Think of it like this: > a TUple needs TWO elements or more. No, a tuple can also be of one element, or even none. You can create a single-element tuple either directly through the use of a t

Re: [Tutor] Dictionaries of Tuples of Strings

2007-02-23 Thread Luke Paireepinart
Tim Golden wrote: > Luke Paireepinart wrote: > >> That's because you can't make tuples of single values. >> Parenthesis are ways of controlling order of operation. >> They don't create tuples unless there's more than one value. > >> Think of it like this: >> a TUple needs TWO elements or more. >> S

Re: [Tutor] Dictionaries of Tuples of Strings

2007-02-23 Thread Bill Sconce
Don't feel bad. Everyone who works with Python bumps into this. And more than once... The preceding reply is correct. But perhaps this is more specific: > TYPES_PYTHON_TO_XML = { >'int':('xs:hexbinary','xs:integer'), >'str':("xs:string") >} The problem is h

Re: [Tutor] Dictionaries of Tuples of Strings

2007-02-23 Thread Tim Golden
Luke Paireepinart wrote: > That's because you can't make tuples of single values. > Parenthesis are ways of controlling order of operation. > They don't create tuples unless there's more than one value. > Think of it like this: > a TUple needs TWO elements or more. > Solution: > use lists. They

Re: [Tutor] Dictionaries of Tuples of Strings

2007-02-23 Thread Luke Paireepinart
Adam Pridgen wrote: > Hello, > > When I have a tuple with a single string in a dictionary entry and > try to iterate over the tuple and it breaks the string into individual > characters. Is this supposed to be happening? > > This problem is a little tricky to explain so I have included the > outpu

[Tutor] Dictionaries of Tuples of Strings

2007-02-23 Thread Adam Pridgen
Hello, When I have a tuple with a single string in a dictionary entry and try to iterate over the tuple and it breaks the string into individual characters. Is this supposed to be happening? This problem is a little tricky to explain so I have included the output and the corresponding example c

Re: [Tutor] dictionaries and memory handling

2007-02-23 Thread Bill Campbell
On Fri, Feb 23, 2007, Alan Gauld wrote: >"Bill Campbell" <[EMAIL PROTECTED]> wrote > >>>It seems that an SQL database would probably be the way to go, but I >>>am a bit concerned about speed issues (even though running time is >> ... >> You would probably be better off using one of the hash databas

Re: [Tutor] dictionaries and memory handling

2007-02-23 Thread Alan Gauld
"Bill Campbell" <[EMAIL PROTECTED]> wrote >>It seems that an SQL database would probably be the way to go, but I >>am a bit concerned about speed issues (even though running time is > ... > You would probably be better off using one of the hash databases, > Berkeley, gdbm, etc. (see the anydbm doc

Re: [Tutor] dictionaries and memory handling

2007-02-23 Thread Bill Campbell
On Fri, Feb 23, 2007, =?ISO-8859-1?Q? Arild_B._N=E6ss ?= wrote: >Hi, > >I'm working on a python script for a task in statistical language >processing. Briefly put it all boils down to counting different >things in very large text files, doing simple computations on these >counts and storing t

[Tutor] dictionaries and memory handling

2007-02-23 Thread Arild B. Næss
Hi, I'm working on a python script for a task in statistical language processing. Briefly put it all boils down to counting different things in very large text files, doing simple computations on these counts and storing the results. I have been using python's dictionary type as my basic d

Re: [Tutor] Dictionaries and aggregation

2006-04-25 Thread Paul Churchill
Right think I've got the idea now. Thanks for all contributions on this. Paul -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Karl "Pflästerer" Sent: 25 April 2006 22:28 To: tutor@python.org Subject: Re: [Tutor] Dictionaries and agg

Re: [Tutor] Dictionaries and aggregation

2006-04-25 Thread Karl Pflästerer
On 25 Apr 2006, [EMAIL PROTECTED] wrote: [...] > Here's the list I'm starting with: > for i in rLst: print i, type(i) > > server001 alive 17.1% 2 requests/s 14805416 total > server001 alive 27.2% 7 requests/s 14851125 total > server002 alive 22.9% 6 requ

Re: [Tutor] Dictionaries and aggregation

2006-04-25 Thread paul . churchill
Kent Johnson writes: >> However here's what I'm now trying to do: >> >> 1) Not have to rely on using awk at all. >> >> >> 2) Create a dictionary with server names for keys e.g. server001, >> server002 etc and the aggregate of the request for that server as the value >> part of t

Re: [Tutor] Dictionaries and aggregation

2006-04-25 Thread Kent Johnson
> However here's what I'm now trying to do: > > 1) Not have to rely on using awk at all. > > > 2) Create a dictionary with server names for keys e.g. server001, > server002 etc and the aggregate of the request for that server as the value > part of the pairing. > > > I got thi

[Tutor] Dictionaries and aggregation

2006-04-24 Thread Paul Churchill
  I am trying to create a dictionary using data produced by a load balancing admin tool and aggregate the results.     When I invoke the tool from within the shell (‘sudo ~/ZLBbalctl --action="" the following output is produced:   Load Balancer 1 usage, over the last 30 seconds Port

Re: [Tutor] Dictionaries versus classes

2006-02-06 Thread Alan Gauld
> In the end my program will have to create a printed representation of a > certain number of "things" ... each thing will also have to have a series > of > other attributes ... which will change during the process of assigning > content (for instance: once content 'A' is assigned to foo, bar > i

Re: [Tutor] Dictionaries versus classes

2006-02-06 Thread Kent Johnson
Michele Alzetta wrote: > In the end my program will have to create a printed representation of a > certain number of "things" which are characterized by each having a time > attribute (moment when they start, moment when they end); each "thing" > will have to be filled in by a certain content, c

[Tutor] Dictionaries versus classes

2006-02-06 Thread Michele Alzetta
Hi all,   after a longish pause I've taken up my pet python project again (must say that the decisive factor was the discovery of how easy it is to code the GUI with QT designer and pyqt).   The core of the problem I'm facing, however, is not the GUI, it is conceptual.   In the end my program will

Re: [Tutor] Dictionaries

2006-01-29 Thread Victor Bouffier
On Fri, 2006-01-27 at 13:20 -0500, Kent Johnson wrote: > It doesn't make much difference for small dictionaries. keys(), values() > and items() create new lists with the specified elements. iterkeys(), > itervalues() and iteritems() create iterators that return the specified > elements in seque

Re: [Tutor] Dictionaries

2006-01-27 Thread Alan Gauld
> their equivalent for keys and values. I notice Ken suggests iteritems(), > while Alan suggests items() only. I'm old fashioned and rarely use new language features until I really have to. Kent uses the more modern idioms. I think iteritems is the preferred usage nowadays, but its longer to type

Re: [Tutor] Dictionaries

2006-01-27 Thread Kent Johnson
Victor Bouffier wrote: > Hi Alan and Ken, > > I think know the difference between using items() vs. iteritems() and > their equivalent for keys and values. I notice Ken suggests iteritems(), > while Alan suggests items() only. > > Does one approach have an advantage over the other? > Should we us

Re: [Tutor] Dictionaries

2006-01-27 Thread Alan Gauld
> ... print '%*s --> %*s' % (maxKey, name, maxValue, pairs[name]) > > thanks for pointing out the '*' syntax. Ignorant as I am I have > had to write things like > > print '%%%ss --> %%%ss' % (maxKey, maxValue) % (name, pairs[name]) I didn't even try that, I've always done it on two lines fmt

Re: [Tutor] Dictionaries

2006-01-27 Thread Victor Bouffier
Hi Alan and Ken, I think know the difference between using items() vs. iteritems() and their equivalent for keys and values. I notice Ken suggests iteritems(), while Alan suggests items() only. Does one approach have an advantage over the other? Should we use only one of them favorably? Thanks.

Re: [Tutor] Dictionaries

2006-01-27 Thread Kent Johnson
Jon Moore wrote: > Hi > > Is there anyway to print informtation from dictionaries better than this?: > > >>> pairs = {"Jon Moore": "Tony Moore", > "Simon Nightingale": "John Nightingale", > "David Willett": "Bernard Willet", > "John Jackson": "Stuart Jackson", >

Re: [Tutor] Dictionaries

2006-01-27 Thread Michael Janssen
On 1/26/06, John Fouhy <[EMAIL PROTECTED]> wrote: > >>> for name in pairs: > ... print '%*s --> %*s' % (maxKey, name, maxValue, pairs[name]) thanks for pointing out the '*' syntax. Ignorant as I am I have had to write things like print '%%%ss --> %%%ss' % (maxKey, maxValue) % (name, pairs[na

Re: [Tutor] Dictionaries

2006-01-26 Thread Alan Gauld
> How would I modify this to just print either the values or keys? Just ask for the values or the keys! for value in pairs.values() print value for key in pairs.keys() print key for key,value in pairs.items() print key print value Dictionaries are extremely powerful data cont

Re: [Tutor] Dictionaries

2006-01-26 Thread Alan Gauld
for father,son in pairs.items: > ... print "%20s\t%20s" % (father,son) Oops! Should have been for father,son in pairs.items(): Sorry, Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Dictionaries

2006-01-26 Thread Kent Johnson
Jon Moore wrote: > Kent > > Thanks! I have not come accross string formatting yet, but I can see how > the for statement works. > > How would I modify this to just print either the values or keys? Use for key in pairs.iterkeys(): or for value in pairs.itervalues(): and change the print st

Re: [Tutor] Dictionaries

2006-01-26 Thread Jon Moore
KentThanks! I have not come accross string formatting yet, but I can see how the for statement works.How would I modify this to just print either the values or keys?Jon On 26/01/06, Kent Johnson <[EMAIL PROTECTED]> wrote: Jon Moore wrote:> Hi>> Is there anyway to print informtation from dictionarie

Re: [Tutor] Dictionaries

2006-01-26 Thread Alan Gauld
> Is there anyway to print informtation from dictionaries better than this?: For formatted printing look at the print format operator '%' You can specify field sizes, justification etc thus : >>> pairs = {"Jon Moore": "Tony Moore", "Simon Nightingale": "John Nightingale", "Da

Re: [Tutor] Dictionaries

2006-01-25 Thread Kent Johnson
Jon Moore wrote: > Hi > > Is there anyway to print informtation from dictionaries better than this?: > > >>> pairs = {"Jon Moore": "Tony Moore", > "Simon Nightingale": "John Nightingale", > "David Willett": "Bernard Willet", > "John Jackson": "Stuart Jackson", >

Re: [Tutor] Dictionaries

2006-01-25 Thread John Fouhy
On 26/01/06, Jon Moore <[EMAIL PROTECTED]> wrote: > Hi > > Is there anyway to print informtation from dictionaries better than this?: Well, you can print the value too if you want :-) eg: >>> pairs = {"Jon Moore": "Tony Moore", ... "Simon Nightingale": "John Nightingale", ... "

[Tutor] Dictionaries

2006-01-25 Thread Jon Moore
Hi Is there anyway to print informtation from dictionaries better than this?:   >>> pairs = {"Jon Moore": "Tony Moore", "Simon Nightingale": "John Nightingale", "David Willett": "Bernard Willet", "John Jackson": "Stuart Jackson", "James Southey": "Richard Southey", 

Re: [Tutor] Dictionaries [Was: Re: string object into reference]

2006-01-17 Thread Victor Bouffier
Hi Danny, On Tue, 2006-01-17 at 16:03 -0800, Danny Yoo wrote: > > > My problem is I want to make a string object into a reference to > > > another object. To be more specific, I'm reading through a text file > > > of amino acids. The first item on each line is the amino acid name, > > > and a la

[Tutor] Dictionaries [Was: Re: string object into reference]

2006-01-17 Thread Danny Yoo
> > My problem is I want to make a string object into a reference to > > another object. To be more specific, I'm reading through a text file > > of amino acids. The first item on each line is the amino acid name, > > and a later item is its exposed surface area. Hi Victor, It sounds like we'd

Re: [Tutor] dictionaries in classes

2005-10-14 Thread w chun
On Fri, 14 Oct 2005, Luke Jordan wrote:>  I'm trying to have functions to create, edit and store dictionaries >  within a class. i 2nd danny's motion:  make your dictionary an instance attribute (unique to that instance) rather than a class attribute (shared amongst all instances), and 2ndly, don't

Re: [Tutor] dictionaries in classes

2005-10-14 Thread Danny Yoo
On Fri, 14 Oct 2005, Luke Jordan wrote: > I'm trying to have functions to create, edit and store dictionaries > within a class. Here's a small example of a class: ## class Person: def __init__(self, name): self.name = name ## Let's try pickling an instance of it: #

  1   2   >