This PEP seems to be gathering dust:
http://www.python.org/dev/peps/pep-0316/
I was thinking the other day, would contracts and invariants not be better than
unit tests? That is, they could do what unit tests do and more, bc they run at
execution time and not just at development time?
--
htt
On 4 Maj, 01:27, [EMAIL PROTECTED] wrote:
> >>> a={1:'a', 2:'b', 3:'c'}
Oops, it should obviously be:
>>> dict(zip(a.values(), a.keys()))
{'a': 1, 'c': 3, 'b': 2}
--
http://mail.python.org/mailman/listinfo/python-list
Assuming all the values are unique:
>>> a={1:'a', 2:'b', 3:'c'}
>>> dict(zip(a.keys(), a.values()))
{1: 'a', 2: 'b', 3: 'c'}
The problem is you obviously can't assume that in most cases.
Still, zip() is very useful function.
--
http://mail.python.org/mailman/listinfo/python-list
(this is a repost, for it's been a while since I posted this text via
Google Groups and it plain didn't appear on c.l.py - if it did appear
anyway, apols)
So I set out to learn handling three-letter-acronym files in Python,
and SAX worked nicely until I encountered badly formed XMLs, like with
bad
So I set out to learn handling three-letter-acronym files in Python,
and SAX worked nicely until I encountered badly formed XMLs, like with
bad characters in it (well Unicode supposed to handle it all but
apparently doesn't), using http://dchublist.com/hublist.xml.bz2 as
example data, with goal to
Glauco wrote:
> cache = None
>
> def lookup( domain ):
> if not cache:
>cache = dict( [map( lambda x: x.strip(), x.split(':')) for x in
> open('/etc/virtual/domainowners','r').readlines()])
> return cache.get(domain)
Neat solution! It just needs small correction for empty or ba
> >>> def shelper(line):
> ... return x.replace(' ','').strip('\n').split(':',1)
Argh, typo, should be def shelper(x) of course.
--
http://mail.python.org/mailman/listinfo/python-list
> I guess Duncan's point wasn't the construction of the dictionary but the
> throw it away part. If you don't keep it, the loop above is even more
> efficient than building a dictionary with *all* lines of the file, just to
> pick one value afterwards.
Sure, but I have two options here, none of
> The csv module is your friend.
(slapping forehead) why the Holy Grail didn't I think about this? That
should be much simpler than using SimpleParse or SPARK.
Thx Bruno & everyone.
--
http://mail.python.org/mailman/listinfo/python-list
Duncan Booth wrote:
> Just some minor points without changing the basis of what you have done
> here:
All good points, thanks. Phew, there's nothing like peer review for
your code...
> But why do you construct a dict from that input data simply to throw it
> away?
Because comparing strings for
Hello everyone,
I have written this small utility function for transforming legacy
file to Python dict:
def lookupdmo(domain):
lines = open('/etc/virtual/domainowners','r').readlines()
lines = [ [y.lstrip().rstrip() for y in x.split(':')] for x in
lines]
lines = [ x for x
Hello everyone,
I'm trying to do seemingly trivial thing with descriptors: have
another attribute updated on dot access in object defined using
descriptors.
For example, let's take a simple example where you set an attribute s
to a string and have another attribute l set automatically to its
leng
> > c=' abcde abc cba fdsa bcd '.split()
> > dels='ce '
> > for j in dels:
> >cp=[]
> >for i in xrange(0,len(c)-1):
>
> The "-1" looks like a bug; remember in Python 'stop' bounds
> are exclusive. The indexes of c are simply xrange(len(c)).
Yep. Just found it out, though this seems a bi
On 30 Wrz, 20:27, William James <[EMAIL PROTECTED]> wrote:
> On Sep 30, 8:53 am, [EMAIL PROTECTED] wrote:
> E:\Ruby>irb
> irb(main):001:0> ' abcde abc cba fdsa bcd '.split(/[ce ]/)
> => ["", "ab", "d", "", "ab", "", "", "ba", "fdsa", "b", "d"]
That's acceptable only if you write perfect ruby-to-p
> > ['ab', 'd', '', 'ab', '', '']
>
> Given your original string, I'm not sure how that would be the
> expected result of "split c on the characters in dels".
Oops, the inner loop should be:
for i in xrange(0,len(c)):
Now it works.
> >>> c=' abcde abc cba fdsa bcd '
> >>> import re
> >>
Hello everyone,
OK, so I want to split a string c into words using several different
separators from a list (dels).
I can do this the following C-like way:
>>> c=' abcde abc cba fdsa bcd '.split()
>>> dels='ce '
>>> for j in dels:
cp=[]
for i in xrange(0,len(c)-1):
16 matches
Mail list logo