George Sakkis <[EMAIL PROTECTED]> writes:
> On May 31, 4:19 am, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
>> Cameron <[EMAIL PROTECTED]> writes:
>> > I was reading this http://www.paulgraham.com/icad.html";>Paul
>> > Graham article and h
):
'''deals x amount of cards(num) to each hand'''
hands = []
for i in range(num_of_hands):
newhand = Hand('hand%d' % i)
self.deal(newhand, num)
hands.append(newhand)
print '%s' % (handname.label), '\n', handname, '\n'
return Hand
Then you can write:
>>> hands = deck.deal_cards(4, 5) # On fait une belotte?
And I don't see the need of defining 'Hand' inside 'Deck'.
HTH
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
And each one has his area of 'work'
>
>
> Thanks for your help !
Python, of course.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
To be Pythonic here, "eloquent" code would perhaps often have clear,
> clean list comprehensions used when "good" code would use a "for"
> loop but still be easy to follow as well and perfectly acceptable in
> the vast majority of cases.
I find that eloquent Python speakers often tend to write a for loop
when mere good ones will try to stick a list comprehension in!
Regards
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
On Apr 3, 11:10 am, João Neves <[EMAIL PROTECTED]> wrote:
> On Apr 3, 4:43 am, Scott David Daniels <[EMAIL PROTECTED]> wrote:
>
> > Nope: If you change the code in-place, the whole stack's references
> > to where they were running would need to get updated to corresponding
> > locations in the new
ctionary *objects*, not *names*,
so write
for a in [dictFoo, dictBar, dictFrotz]:
...
BTW, hasattr() is not what you want as it check the existence of an
attribute, i.e. a.hasattr('x') means that a.x exists; you could write
the whole thing as:
for a in dictFoo, dictBar, dictFrotz:
thougth enough on it. Looks fine in principle, but
> yield expressions may be a problem.
>
> --
> Gabriel Genellina
Funnily, there's a patch for py3k to make this work as in your idea.
It's currently being discussed on python-3000 :)
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
RWTH - Aachen University
> D 52056 Aachen, Germany
This is in the top two FAQ, here is the relevant section:
http://www.python.org/doc/faq/programming/#how-do-i-create-a-multidimensional-list
HTH
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
ition:
recfun(lines)
lines = iter(open(filename))
recfun(lines)
Or if you want the filename to be the argument of you function, wrap
it in a non-recursive function:
def fun(filename):
lines = iter(open(filename))
def recfun():
for line in lines:
# Do stuff
On Apr 7, 2:09 pm, [EMAIL PROTECTED] wrote:
> Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
> > def recfun(lines):
> > for line in lines:
> > # Do stuff
> > if condition:
> > recfun(lines)
>
> > lines = iter(open(filena
break;
> > #
> > # do various tests
> > #
> > if :
> > recfun(f)
>
> Don't do that; Python doesn't have tail recursion and you'll hit the
> stack limit.
>
> John Nagle
This function is not tail recursive (the recursive call is in a loop).
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
x))
> print(∑(values))
> near = λ a,b,ε=0.01: a-ε ≤ b ≤ a+ε
It's all in the eye of the beholder: to me it looks readable, but
that's because I've spent 10 years of my life reading and writing
stuff like that. Although I would use ∀ and ∃ as aliases for all()
and exists() :)
-
On Apr 8, 6:47 am, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
[...]
> Although I would use ∀ and ∃ as aliases for all()
> and exists() :)
I mean all() and any() of course
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
something entered by user. now i want to call FB. I don't
> want to do an if else because if have way too many methods like
> this...
>
> var = "F" + temp
> var(param1, param2)
>
> This does not work ofcourse. Does anyone know how to implement this
aron
Bytecodes:
http://docs.python.org/lib/bytecodes.html
VM:
Python/ceval.c
HTH
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
in enumerate(f):
# Do stuff
How to find out about it? I suppose you need to get familiar with
python iterators/iterables and the functions to manipulate them. How
to do that depends on your prior experience with such concepts.
Unfortunately I am not able to provide you with a good link :(
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
fficient extraction
> of any one of the 3 digits. Decimal doesn't use this either. :)
>
> Mark
Naive question: why not just use a long + an exponent?
e.g. 132560 -> (13256, 1)
0.534 -> (534, -3)
5.23e10 -> (523, 8)
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
operty
def bar(self):
return self._bar
@bar.setter
def setbar(self, x):
self._bar = '<%s>' % x
# Interactive test -
>>> foo = Foo()
>>> foo.bar = 3
>>> foo.bar
'<3>'
>>> foo.bar = 'oeufs'
>>> foo.bar
''
>>>
Having fun'ly yours,
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
return 3
class Leaf2(Branch):
pass
- Test -
>>> totalscore(Root, 1)
0
>>> totalscore(Branch, 1)
1
>>> totalscore(Leaf, 1)
4
>>> totalscore(Leaf2, 1)
1
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
27;propset' decorator function.
> self._x = v + 1
>
> Now enter the interpreter:
> >> import mod
> >>> f = mod.Foo()
> >>> f.x = 4
> >>> f.x
>
> 4
>
> I don't feel like giving up on this now, so close...
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
me saves nine.
> A BAR in time saves nine.
>
> I suppose I could set the default to a string literal, test for it and if
> true assign the value of self.default to keyword; however, that seems
> clunky. Any ideas how this could be done along the lines of my proposed
> but faulty cod
finitions. (And if you're not using conventional definitions, you
> should say so)
And I would like to know what unconventional - but mathematically
meaningful - definitions lead to
lim x != 0
x -> 0
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
want to have
> to access them as functions rather than variables or properties.
Metaclasses, of course!
>>> class MetaX(type):
... @property
... def spam(self): return 'eggs'
...
>>> class X(object):
... __metaclass__ = MetaX
...
>>> X.spam
'eggs'
>>>
HTH
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
On Apr 13, 12:33 am, Charles D Hixson <[EMAIL PROTECTED]>
wrote:
> Arnaud Delobelle wrote:
> >>>> class MetaX(type):
>
> > ... @property
> > ... def spam(self): return 'eggs'
> > ...
>
> >>>> class X(object):
ython
> 2.3.
Django only requires Python 2.3 IIRC, and I think you can use it with
FastCGI instead of mod_python. Doesn't FastCGI only require apache
1.3.x ?
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
object):
... @classmethod
... def bar(cls): print 'Oh my Baz!'
...
>>> globals()['Foo']
>>> globals()['Foo'].bar()
Oh my Baz!
If your class lives in a module, just do getattr(module, classname)
instead to get the class object.
HTH
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
On Apr 13, 5:35 pm, Ivan Illarionov <[EMAIL PROTECTED]> wrote:
> On Mar 19, 2:17 pm, "BJörn Lindqvist" <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Mon, Mar 17, 2008 at 11:57 PM, Arnaud Delobelle
>
> > <[EMAIL PROTECTED]> wrote:
> > >
fore expression is parsed.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
choose from that two possibilities with equal probability.
> So when we round 2.5 we are actually rounding an interval which could
> be equally be rounded to 2 or to 3, and the same for 3.5, 4.5 etc. If
> the number of such intervals is big, choosing the even number helps to
> make as ma
#x27;list' is the type of lists, it is also a 'constructor'
for list objects (the same goes for other common buit-in types, such
as 'int', 'float', 'str', 'tuple', 'dict').
E.g.
>>> foo = [1, 2, 3]
>>> bar = list(foo)
>>> foo[0] = 4
>>> foo
[4, 2, 3]
>>> foo = [1, 2, 3]
>>> bar = list(foo)
>>> bar[0] = 4
>>> bar
[4, 2, 3]
>>> foo
[1, 2, 3]
>>>
HTH
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
do some group manipulation of fields (e.g. print them
all
def print_fields(self):
for name, value in self._fields.iteritems():
print "%s: %s" % (name, value)
)
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
dictionaries (rhm.__dict__ then
RequestHeadersManager.__dict__).
--
Arnaud
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
e something like this:
class Ruleset(list):
def add(self, regexp):
def decorator(func):
self.append((regexp, func))
return func
return decorator
class Parser(object):
rules = Ruleset()
@rules.add(r'".*"')
def quoted_string(self):
> del instanceList # You can try: nothing is freed by this
> """
> ??? How do you people control python to free the memory in python 2.5 or
> python 2.4 ???
> Cheers!!!
You mistyped your subject line; it should have read:
"Help needed - I don't understand how Python manages memory"
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
eme in .py files, so it seems to
> me that this doesn't have to be done in the core language. All that's
> needed is a variant of 'eval' which expects the alternate scheme, and
> that could be prototyped just using text manipulation and the normal
> 'eval'.
By 'eval', I guess you mean 'exec' :)
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
On Apr 20, 7:54 pm, <[EMAIL PROTECTED]> wrote:
[...]
> python should have stayed at version 1.5, every single 'improvement'
> has been a mess. But this is the definitive hell.
You can still download Python 1.5.2 from python.org:
http://www.python.org/download/release
.
clafoutis = Recipe('eggs', 'spam')
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
if it
> does not exist, it may return only empty, just as in php
At the interactive prompt, type 'help(dict)' and read carefully about
the different methods provided by dictionary objects (one called 'get'
may be of particular interest to you).
HTH
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
ith regexps, but my simpleminded )]+/> doesn't work. I'm not
> enough of a regexp pro to figure out that lookahead stuff.
Hi, I'm not sure if this is very helpful but the following works on
the very simple example below.
>>> import re
>>> xhtml = 'hell
in expand(recfilename):
yield recline
elif line.startswith('#define '):
_, name, value = line.strip().split(None, 2)
defines[name] = value
else:
yield define_regexp.sub(define_repl, line)
It would be easy to modify it to keep track of line numbers and file
names.
HTH
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
fallen victim to the Name Mangling Trap [1]. Replace the
leading double underscore in the __name attribute with a single one,
and Python shall calm down and let your code behave as you expect it
to.
That is, if you also pass the name parameter to super(A,self).__init__
in B's __init__ method
[1] http://docs.python.org/ref/atom-identifiers.html
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
Arnaud Delobelle <[EMAIL PROTECTED]> writes:
> That is, if you also pass the name parameter to super(A,self).__init__
> in B's __init__ method
Oops. should be super(B, self).__init__(name), of course.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
By
design, python doesn't include mechanisms equivalent to the Java / C++
'private'.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
def getprimes(N):
arr = range(N+1)
arr[1] = 0
for s in xrange(2, int(math.sqrt(N))+1):
if arr[s]:
arr[s*s : N+1 : s] = [0] * (N/s - s + 1)
return filter(None, arr)
(I think)
This all needs to be tested.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
gt;
> Also should I be using regex at all here ?
If every line of the file is of the form name=value, then regexps are
indeed not needed. You could do something like that.
params = {}
for line in file:
name, value = line.strip().split('=', 2)
params[name] = value
(untested
Joshua Kugler <[EMAIL PROTECTED]> writes:
[...]
> self.me = []
> for v in obj:
> self.me.append(ObjectProxy(v))
Note that is could be spelt:
self.me = map(ObjectProxy, v)
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
Chris Henry <[EMAIL PROTECTED]> writes:
> On Apr 25, 8:37 pm, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
>> micron_make <[EMAIL PROTECTED]> writes:
>> > I am trying to parse a file whose contents are :
>>
>> > parameter=current
>> > ma
[EMAIL PROTECTED] (Aahz) writes:
> In article <[EMAIL PROTECTED]>,
> Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
>>Joshua Kugler <[EMAIL PROTECTED]> writes:
>>>
>>> self.me = []
>>> for v in obj:
>>>
method of strings:
>>> path = r'C:\myimages\imageone.jpg'
>>> path.rsplit('.', 1)
['C:\\myimages\\imageone', 'jpg']
>>> path = r"C:\blahblah.blah\images.20.jpg"
>>> path.rsplit('.', 1)
['C:\\blahblah.blah\\images.20', 'jpg']
HTH
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
om.choice(meths)
> c.ch()
This will work:
getattr(c, ch)()
Getattr(c, "meth1") is equivalent to c.meth1. Or you could do:
meths = [c.meth1, c.meth2]
ch = random.choice(meths)
ch()
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
27;foo.baz/bar'.rsplit('.')
['foo', 'baz/bar']
>>> os.path.splitext('foo.baz/bar')
('foo.baz/bar', '')
Conclusion: forget about str.rsplit() (which I suggested), use
os.path.splitext() instead :)
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
['book', 'textbook', 'notepad'], ['pencil', 'pen', 'pacer'] ]
# these words will be replaced with nothing
wordmap = dict((w, []) for w in un_words)
# these words will be replaced with the list of their synonyms
for wordlist in alterns:
for word in wordlist:
wordmap[word] = wordlist
def compareandremove(sentence):
return [x for w in sentence.split() for x in wordmap.get(w, [w])]
# Example
>>> compareandremove('notepad a pencil with desk')
['book', 'textbook', 'notepad', 'pencil', 'pen', 'pacer', 'desk']
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
'You! are Free??'.translate(table, '!?')
'you are free'
HTH
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
functions to methods and use getattr( myClass, "method" )
>
> 3. Place all my functions in dictionary and lookup the function to be
> called
4. Put all my functions in a module and use getattr(module, 'function')
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
[EMAIL PROTECTED] writes:
> Is there an elegant way to unget a line when reading from a file/stream
> iterator/generator?
>
> By "unget" I mean a way to push back a line into the source stream and
> backtrack the iterator/generator one step?
>
> The only alternative I can see is to put my line rea
one
>
> Please explain this behavior. range(5) returns a list from 0 to 4 and
> reverse just reverses the items on the list that is returned by
> range(5). Why is x None (null)?
have you tried typing help(list.reverse) at the interactive prompt?
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
throws error:
> :No such file or directory
>
> I am editing file from eclipse for python from windows. and then
> uploading on linus machine to run it.
>
>
> any pointers?
Have you made your file executable (man chmod)?
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
t; Thanks again to everyone who contributed on this thread.
>
> Regards,
> Malcolm
You could avoid #5 from the start using a decorator:
functions = {}
def register(func):
functions[func.__name__] = func
return func
@register
def foo(): print "Foo!"
@register
e objects (similar to
> javascript), that type casting is done through build-in functions
> rather than methods, e.g. String.toInt('5') or '5'.toInt() or x =
> Integer.fromString('5').
Because Python is not Javascript?
In fact some are methods, e.g. str(x) is shorthand for x.__str__().
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
ne here:
marigold:junk arno$ python
Python 2.5.1 (r251:54863, Jan 17 2008, 19:35:17)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> unsafe_chars = "/#()[EMAIL PROTECTED]&*{}
destroy <[EMAIL PROTECTED]> writes:
> On Apr 29, 4:50 pm, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
>>
>> marigold:junk arno$ python
>> Python 2.5.1 (r251:54863, Jan 17 2008, 19:35:17)
>> [GCC 4.0.1 (Apple Inc. build 5465)] on darwin
>> Type &q
very reasonable place to search; I think chr and ord are
> builtin functions (and not str methods) just by an historical
> accident. (Or is there any other reason? what's wrong with "a".ord()
> or str.from_ordinal(65))?
Not a reason, but doesn't ord() word with unicode as well?
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
" + param2
> def FA(param1,param2):
> print "FC" + param1 + " " + param2
>
> temp = sys.argv[1]
>
> func = globals()["F" + temp]
> func("Hello", "World")
>
>
> I ran the script with first parameter as B and i get
ool effect when you're 12!
CLV
LOOP: INC $D020
BVC LOOP
(from memory, untested!)
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
fusing gmail addresses and Google Groups
(groups.google.com), which can be used as a web interface to usenet
and mailing lists. Look at the 'Organisation' header of the messages
you quote.
It seems most of the spam on comp.lang.python is posted from Google
Groups, *including* the one with a 'From' header which is not a gmail
address.
So it would be more efficient to block messages posted from Google
Groups than the ones from gmail addresses.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> writes:
> On Fri, 02 May 2008 19:23:54 +0100, Arnaud Delobelle wrote:
>
>> Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> writes:
>>
>>>
>>> There are no modern processors with an opc
vát
sum() works for any sequence of objects with an __add__ method, not
just floats! Your algorithm is specific to floats.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
Szabolcs Horvát <[EMAIL PROTECTED]> writes:
> Arnaud Delobelle wrote:
>>
>> sum() works for any sequence of objects with an __add__ method, not
>> just floats! Your algorithm is specific to floats.
>
> This occurred to me also, but then I tried
>
> sum([
over keys and values using the items() or
iteritems() method of dictionaries:
def invert(d):
inv = {}
for key, val in d.iteritems():
inv.setdefault(val, []).append(key)
return inv
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
lines.add(line)
for i in xrange(25):
line = shift1(line)
if line in lines:
print line
(untested)
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
ere keys are
> "".join(sorted(word))
> Such general strategy to look for a possible invariant key for the
> subsets of the required solutions is quite useful.
Or even:
def get_key(word):
initial = ord(word[0])
return tuple((ord(x) - initial) % 26 for x in word[1:])
--
Arn
George Sakkis <[EMAIL PROTECTED]> writes:
> On May 5, 11:02 pm, dave <[EMAIL PROTECTED]> wrote:
>> On 2008-05-04 01:10:40 -0600, Arnaud Delobelle <[EMAIL PROTECTED]> said:
>>
>>
>>
>> > dave <[EMAIL PROTECTED]> writes:
>>
>&g
n truth, even without multiple inheritance, Python
wouldn't need java-like interfaces.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
ehind the scene?).
Else you could use a trampoline, as I've done here:
http://www.marooned.org.uk/~arno/python/cogenerator.html
(Scroll down to 'Flattening nested cogenerators' and 'recursive
cogenerators' - I had fun doing it but it is terribly inefficient).
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
xcellent!)
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
ne in open('bigfile'))
sum(1 for line in ifilter(search, open('bigfile')))
...etc...
All this is untested!
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
herwise it could be a bit simpler:
missing_keys = set(first_dict)
for keys, val in second_dict.iteritems():
for key in keys:
missing_keys.discard(key)
if first_dict.get(key, val) != val:
print "wrong value for", key, 'in', keys
if missing_keys:
print 'some keys are missing:', ',',join(remaining)
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
that x is now bound to 2, but it is only apparent
if one closely scrutinises the code.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
onary', but obviously isn'tas it is a list
of key,value pairs.
* length = len(getvals)
Again, we know it's a length, but the length of what?
HTH
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
"Méta-MCI (MVP)" <[EMAIL PROTECTED]> writes:
> Hi!
>
>> I don't often feel like using this word
>
> Look at languages like OCAML or F #
While I like Objective Caml, it is definitively not Python!
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
= 4 # Equivalent to x.__setattr__('a', 4)
What conclusion should we draw from that?
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
Duncan Booth wrote:
> Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
>
> >
> >
> > George Sakkis wrote:
> >> One of the few Python constructs that feels less elegant than
> >> necessary to me is the del statement. For one thing, it is overloaded
>
pistacchio <[EMAIL PROTECTED]> writes:
> ocalm forces you to di OOP
Ocaml *allows* you to do OOP. It's very much an optional feature of
the language, just like for Python.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
ving to think.
> -- Martin Luther King, Jr.
> from "Strength to Love," 1963.
import system
from system import thing
is the same as:
import system
thing = system.thing
Do you expect system.thing to be rebound when you rebind thing?
HTH
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
"Kam-Hung Soh" <[EMAIL PROTECTED]> writes:
> I avoid creating a temporary variable if it's only used once
> immediately, so I would have written:
>
> newtlist = ''.join(sorted(list(line)))
Or ''.join(sorted(line))
as sorted() works wit
e
function from the empty set to the empty set, 0^0 = 1.
The arguments for making 0^0 = 0 are weak, it is a bit more convincing
to want it to be undefined (as (0,0) is a point of discontinuity of
(x,y) -> x^y).
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
list3 that contains
> > > elements from list1 with indexes from list2, i.e.
> >
> > list3 = [list1[i] for i in list2]
> >
> > --
> > Paul Hankin
This works under python 2.0+, I think.
Before that, you could have written:
list3 = map(list1.__getitem__, list2)
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
.join(sorted(word.lower()))
>> anagrams.setdefault(key, []).append(word)
>> return anagrams
>
> What would be the best method to print the top results, the one's that
> had the highest amount of anagrams?? Create a new histogram dict?
You can use the max() function to find the biggest list of anagrams:
top_results = max(anagrams.itervalues(), key=len)
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
Create a new histogram dict?
>>>
>>> You can use the max() function to find the biggest list of anagrams:
>>>
>>> top_results = max(anagrams.itervalues(), key=len)
>>>
>>> --
>>> Arnaud
>>
>> That is the biggest list of anagrams, w
ead class.
>
> When I put the same line in a thread class, it no longer works, and I get
> an error:
>
> IOError: [Errno 2] no such file u'fileName'
>
It's telling you that you haven't got a file called 'fileName'.
Posting the code that triggers this
bc90021 <[EMAIL PROTECTED]> writes:
> On Sun, 11 May 2008 18:36:25 +0100, Arnaud Delobelle wrote:
>
>> bc90021 <[EMAIL PROTECTED]> writes:
>>
>>> Hi All,
>>>
>>> Thanks in advance for any and all help!
>>>
>>> I have t
Arnaud Delobelle <[EMAIL PROTECTED]> writes:
> bc90021 <[EMAIL PROTECTED]> writes:
>
>> On Sun, 11 May 2008 18:36:25 +0100, Arnaud Delobelle wrote:
>>
>>> bc90021 <[EMAIL PROTECTED]> writes:
>>>
>>>> Hi All,
>>&g
file u'tempfileName'
This is different from the error message that you posted in your
original message.
Anyway, what is useful to us is a full traceback, no just an error
message.
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
ind
its variable to something useful instead of an unused counter.
Contrived example:
# Print 'hello' 10 times; x is not used
for x in xrange(10):
print 'hello'
# By changing what is iterated over, no unused variable:
from itertools import repeat
for msg in repeat('hello', 10):
print msg
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
r']
>>> 'C:\\'.split('\\')
['C:', '']
So you could write instead something like
x1 = path1.rstrip(os.sep).split(os.sep)
x2 = path2.rstrip(os.sep).split(os.sep)
in your function
HTH
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
mean?
I guess you are on Windows, but how do you run your script? Do you do
it from the command line or do you use some IDE?
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
attrs = {}
for i in '12':
moreattrs['title_' + i] = int(i)
>>> A.title_1
1
>>> A.title_2
2
>>>
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
little while ago when thinking about this kind of problem I defined
"cogenerators", which roughly are to generators what coroutines are to
routines, i.e. they can pass "yielding control" on to another
cogenerator [1].
[1] http://www.marooned.org.uk/~arno/python/cogenerator.html
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
ve, which of course has no
benefit in Python. In fact it looks like a Scheme implementation of
sum translated literally to Python.
In Python this algorithm is expressed naturally as:
def suma(xs):
acc = 0
for x in xs:
acc += x
return acc
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
t; change the reference to itself, but at least both changes are right next
> to each other.
>
> Assume that changing the function name or the module name are both
> equally likely/unlikely.
>
> Which do other people prefer? Which seems "better" to you? Are there any
>
801 - 900 of 1146 matches
Mail list logo