On 2018-04-26, Alan Gauld via Tutor wrote:
> OTOH its definitely not good OOP, ther are no methods and we
> are just using the class as a record. (A named tuple might
> actually be a better option on reflection.)
namedtuple is great in lots of cases, but sometimes it transpires
I wish to make alt
On 26/04/18 14:48, Mats Wichmann wrote:
>>> However personally I'd use a class to define your data structure and
>>> just have a top level dictionary holding instances of the class.
>>
>> You are right (again). I haven't thougt of using classes, but that's exactly
>> what they were invented for. T
On 04/25/2018 12:46 PM, Kai Bojens wrote:
> On 25/04/2018 –– 18:35:30PM +0100, Alan Gauld via Tutor wrote:
>>> ...
>>> for line in logfile:
>>> result = pattern.search(line)
>
>> Doesn't this overwrite your data structure?
>> I would strongly advise using another name.
>
> You are of
On 25/04/2018 –– 18:35:30PM +0100, Alan Gauld via Tutor wrote:
> > ...
> > for line in logfile:
> > result = pattern.search(line)
> Doesn't this overwrite your data structure?
> I would strongly advise using another name.
You are of course right. I accidentally shortened this name as
On 25/04/18 14:22, Kai Bojens wrote:
> The structure I'd like to have:
>
> result = {
> 'f...@bar.de': {
> 'Countries': [DE,DK,UK]
> 'IP': ['192.168.1.1','172.10.10.10']
> 'Count': [12]
> }
> }
> ...
> for line in logfile:
>
Hello everybody,
I'm coming from a Perl background and try to parse some Exim Logfiles into a
data structure of dictionaries. The regex and geoip part works fine and I'd
like to save the email adress, the countries (from logins) and the count of
logins.
The structure I'd like to have:
result = {
>
> Is it possible to sort dict & to get result as dict?
> if it is possible, please give some example.
>
Just to understand the question more, can you give more details? Why would
you want a sorted dict?
That is, it is not directly obvious what your intent is yet, so you need to
say more. Are
On Tue, Nov 26, 2013 at 04:37:28PM +0530, Sunil Tech wrote:
> Hi Friends,
>
> Is it possible to sort dict & to get result as dict?
> if it is possible, please give some example.
No it is not possible, dicts are deliberately unsorted.
Please read my explanation why from yesterday:
https://mail.p
Hi,
> Is it possible to sort dict & to get result as dict?
> if it is possible, please give some example.
By what do you want to sort it? By key? By value? By a combination of
both?
Cheers,
Nik
--
Ein Jabber-Account, sie alle zu finden; ins Dunkel zu treiben
und ewig zu binden; im Nat
Hi Friends,
Is it possible to sort dict & to get result as dict?
if it is possible, please give some example.
Thank you in advance.
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/li
On 02/18/2012 03:39 AM, Peter Otten wrote:
Leam Hall wrote:
On 02/17/2012 09:26 AM, Dave Angel wrote:
There are two ways to think of a class. One is to hold various related
data, and the other is to do operations on that data. If you just
consider the first, then you could use a class like a d
Leam Hall wrote:
> On 02/17/2012 09:26 AM, Dave Angel wrote:
>> There are two ways to think of a class. One is to hold various related
>> data, and the other is to do operations on that data. If you just
>> consider the first, then you could use a class like a dictionary whose
>> keys are fixed (k
Leam Hall wrote:
I'm building a program that uses one of my own modules for a bunch of
formula defs and another module for the tkinter GUI stuff. There are
half a dozen input variables and about the same in calculated variables.
Is it better/cleaner to just build a global dict and have everythi
On 02/17/2012 09:26 AM, Dave Angel wrote:
There are two ways to think of a class. One is to hold various related
data, and the other is to do operations on that data. If you just
consider the first, then you could use a class like a dictionary whose
keys are fixed (known at "compile time").
I t
On 17/02/12 14:10, leam hall wrote:
The variables input seem to be assumed to be strings
They are not assumed to be strings, they *are* strings. Users can only
type characters at the keyboard (the usual source of input). Your
program has to interpret those characters and convert to the right
leam hall wrote:
> On 2/17/12, Peter Otten <__pete...@web.de> wrote:
>> leam hall wrote:
>>> and they may have to have their type set
>>
>> I have no idea what you mean by "have their type set". Can you give an
>> example?
>
> Peter,
>
> The variables input seem to be assumed to be strings and I
On 02/17/2012 09:06 AM, leam hall wrote:
On 2/17/12, Dave Angel wrote:
Real question is whether some (seldom all) of those variables are in
fact part of a larger concept. If so, it makes sense to define a class
for them, and pass around objects of that class. Notice it's not
global, it's sti
On 2/17/12, Peter Otten <__pete...@web.de> wrote:
> leam hall wrote:
>> and they may have to have their type set
>
> I have no idea what you mean by "have their type set". Can you give an
> example?
Peter,
The variables input seem to be assumed to be strings and I need them
to be an integer or a
On 2/17/12, Dave Angel wrote:
> Real question is whether some (seldom all) of those variables are in
> fact part of a larger concept. If so, it makes sense to define a class
> for them, and pass around objects of that class. Notice it's not
> global, it's still passed as an argument. This can
leam hall wrote:
> My concern with variables is that they have to be passed in specific
> order to the function,
Yes, unless you use keywords. You can invoke
def div(x, y):
return x // y
a = div(3, 2)
b = div(y=3, x=2)
assert a == b
> and they may have to have their type set
I have no ide
On 2/17/12, Peter Otten<__pete...@web.de> wrote:
Leam Hall wrote:
I'm building a program that uses one of my own modules for a bunch of
formula defs and another module for the tkinter GUI stuff. There are
half a dozen input variables and about the same in calculated variables.
Is it better/c
On 17 February 2012 14:04, leam hall wrote:
> My concern with variables is that they have to be passed in specific
> order to the function, and they may have to have their type set
> multiple times so that you can perform the right functions on them. In
> a dict you could set it on insert and not
Thanks Peter!
My concern with variables is that they have to be passed in specific
order to the function, and they may have to have their type set
multiple times so that you can perform the right functions on them. In
a dict you could set it on insert and not have to worry about it.
Thanks!
Leam
Leam Hall wrote:
> I'm building a program that uses one of my own modules for a bunch of
> formula defs and another module for the tkinter GUI stuff. There are
> half a dozen input variables and about the same in calculated variables.
> Is it better/cleaner to just build a global dict and have eve
I'm building a program that uses one of my own modules for a bunch of
formula defs and another module for the tkinter GUI stuff. There are
half a dozen input variables and about the same in calculated variables.
Is it better/cleaner to just build a global dict and have everything go
into it or
Steven, Alan, Knacktus,
thanks for your help. I was indeed very confused because I thought
'_find' was calling something special instead of just being added to
the dictionary (the confusion stemming from
http://www.python.org/dev/peps/pep-0004/ where find module is
obsolete).
When I ran the code,
Am 20.02.2011 05:14, schrieb Max Niederhofer:
Hello all,
Hello Max,
first post, please be gentle. I'm having serious trouble finding an
alternative for the deprecated find module for dictionaries.
The code (from Zed Shaw's Hard Way, exercise 40) goes something like
this. Hope indentation sur
"Max Niederhofer" wrote
first post, please be gentle. I'm having serious trouble finding an
alternative for the deprecated find module for dictionaries.
I think you are misunderstanding some of the terminology.
There is no deprecated find module. You are not using
any modules in your code. An
Max Niederhofer wrote:
Hello all,
first post, please be gentle. I'm having serious trouble finding an
alternative for the deprecated find module for dictionaries.
What find module for dictionaries?
The code (from Zed Shaw's Hard Way, exercise 40) goes something like
this. Hope indentation
Hello all,
first post, please be gentle. I'm having serious trouble finding an
alternative for the deprecated find module for dictionaries.
The code (from Zed Shaw's Hard Way, exercise 40) goes something like
this. Hope indentation survives.
cities = {'CA': 'San Francisco', 'MI': 'Detroit', 'FL'
On Fri, 24 Sep 2010 01:45:29 am you wrote:
> > Oh, and (4)... in Python circles, it's traditional but not
> > compulsory to use metasyntactic variables named after Monty Python
> > sketches rather than foo and bar. So spam, ham, eggs, parrot (dead
> > or otherwise), names of cheeses, aardvark..., a
> Oh, and (4)... in Python circles, it's traditional but not compulsory
> to use metasyntactic variables named after Monty Python sketches
> rather than foo and bar. So spam, ham, eggs, parrot (dead or
> otherwise), names of cheeses, aardvark..., although there is no
> standard order.
Hm, some
On Thu, 23 Sep 2010 09:21:27 am Pete wrote:
> > (3) There's no need to keep the instances floating around as
> > independent names, unless you need direct access to them.
> >
> > Putting these together, we get:
> >
> > dispatch_table = { 'foo': foo().do, 'bar': bar().do }
[...]
> I see. And are th
On 2010-09-22, at 5:50 PM, Steven D'Aprano wrote:
> On Thu, 23 Sep 2010 06:07:21 am Pete wrote:
>> For a plugin mechanism, I'm populating a dict with calls to the
>> implemented plugins.
> [...]
>> Now I get that I need to instantiate foo and bar first before I can
>> refer to them in the dict.
>
On Thu, 23 Sep 2010 06:07:21 am Pete wrote:
> For a plugin mechanism, I'm populating a dict with calls to the
> implemented plugins.
[...]
> Now I get that I need to instantiate foo and bar first before I can
> refer to them in the dict.
>
> so something like
>
> foo_instance = foo()
> bar_instance
For a plugin mechanism, I'm populating a dict with calls to the implemented
plugins.
Consider this:
>>> class foo:
... def do(self):
... print 'do foo'
...
>>> class bar:
... def do(self):
... print 'do bar'
...
>>> list = { 'foo': foo.do(), 'bar': bar.do() }
T
On Wed, Jan 21, 2009 at 10:54 PM, wormwood_3 wrote:
> When creating a list of dictionaries through a loop, I ran into a strange
> issue. I'll let the code talk:
t = []
for thing in l:
> ... t.append(dict(thing=1))
> ...
t
> [{'thing': 1}, {'thing': 1}, {'thing': 1}, {'thing': 1
to complain that it didn't get a string or an int as it expects for
a keyword argument? Maybe I am missing the use case, so far it just seems
strange to force the keyword to a string.
-Sam
------
From: bob ga
dictionary equal to {"one": 2, "two": 3}:
...
dict(one=2, two=3)
From: bob
gailer
To: wormwood_3
Cc: Python Tutorlist
Sent: Wednesday,
January 21, 2009 11:02:35 PM
Subject: Re: [Tutor]
dict() versus {}
wormwood_3 wrote:
When
creating a li
al to {"one": 2, "two": 3}:
...
dict( two=3)
From: bob
gailer
To: wormwood_3
Cc: Python Tutorlist
Sent: Wednesday,
January 21, 2009 11:02:35 PM
Subject: Re: [Tutor]
dict() versus {}
wormwood_3 wrote:
When
creating a list of dictionaries thr
hotos - http://www.flickr.com/photos/samuelhuckins/
AIM - samushack | Gtalk - samushack | Skype - shuckins
From: bob gailer
To: wormwood_3
Cc: Python Tutorlist
Sent: Wednesday, January 21, 2009 11:02:35 PM
Subject: Re: [Tutor] dict() versus {}
wormwood_3 wrote:
wormwood_3 wrote:
When
creating a list of dictionaries through a loop, I ran into a strange
issue. I'll let the code talk:
>>> l = 'i am a special new list'.split()
>>> t = []
>>> for thing in l:
... t.append({thing: 1})
...
>>> t
[{'i': 1}, {'am': 1}, {'a': 1}, {'special': 1}, {'
When creating a list of dictionaries through a loop, I ran into a strange
issue. I'll let the code talk:
>>> l = 'i am a special new list'.split()
>>> t = []
>>> for thing in l:
... t.append({thing: 1})
...
>>> t
[{'i': 1}, {'am': 1}, {'a': 1}, {'special': 1}, {'new': 1}, {'list': 1}]
This
Kent Johnson wrote:
> My understanding of the OP is that he wants an exception if there are items
> in errdict. Also this solution will change self.somedict even in the error
> case which may not be desirable.
I understood what the OP said but think he expressed himself incorrectly or
the alg
Really I was just wondering if this was a bad practice or if there was
some way to get the same result.
So if the list comprehension isn't a bad way to to it then I will
stick with it.
I am at the point where I have used python for simple stuff for a few
years and I am attempting to get past a n
Javier Ruere wrote:
> I should also add the most simple and obvious implementation which is also
> the fastest:
>
>
> class Test:
> def __init__(self, dict):
> self.somedict = dict
>
> def updateit(self, **mydict):
> errdict = {}
> for k, v in mydict.iteritems():
David Driver wrote:
> I have a function
>
> def updateit(self,**mydict):
>
> which is intended to update a dictionary self.somedict.
>
> If there are keys in mydict that are not in self.somedict I want them
> returned in a new dict.
>
> here is what i am doing now:
>
> errdict = dict([(a,b) f
I should also add the most simple and obvious implementation which is also the
fastest:
class Test:
def __init__(self, dict):
self.somedict = dict
def updateit(self, **mydict):
errdict = {}
for k, v in mydict.iteritems():
if k not in self.somedict:
David Driver wrote:
> I have a function
>
> def updateit(self,**mydict):
>
> which is intended to update a dictionary self.somedict.
>
> If there are keys in mydict that are not in self.somedict I want them
> returned in a new dict.
>
> here is what i am doing now:
>
> errdict = dict([(a,b) f
I have a function
def updateit(self,**mydict):
which is intended to update a dictionary self.somedict.
If there are keys in mydict that are not in self.somedict I want them
returned in a new dict.
here is what i am doing now:
errdict = dict([(a,b) for a,b in mydict.items() if not a in self.so
50 matches
Mail list logo