On Fri, 20 Aug 2010 09:51:08 am Pete wrote:
[...]
> Ah, so list comprehensions are a purely syntactic construct?
No, I don't think that's what Emile was trying to say. It's not like
list comps are macros that are expanded into the explicit for-loop like
that. All he is saying is that both the f
On 2010-08-19, at 5:25 PM, Emile van Sebille wrote:
> On 8/19/2010 7:51 AM Pete said...
>> Hi,
>>
>> I've been reading up on list comprehensions lately, all userful and powerful
>> stuff - trying to wrap my brain around it :)
>>
>> As the examples all seem to relate to lists, I was wondering if
On 8/19/2010 7:51 AM Pete said...
Hi,
I've been reading up on list comprehensions lately, all userful and powerful
stuff - trying to wrap my brain around it :)
As the examples all seem to relate to lists, I was wondering if there is an
elegant similar way to apply a function to all keys in a
Roelof Wobben wrote:
def is_odd(argument):
uitkomst=is_even(argument)
return uitkomst
You forgot to indent the return statement to match the other
statement(s) in the function.
DaveA
___
Tutor maillist - Tutor@python.org
To un
On 8/19/10, Roelof Wobben wrote:
>
> Hello,
>
>
>
> I have this exercise:
>
>
>
> Now write the function is_odd(n) that returns True when n is odd and False
> otherwise. Include doctests for this function as you write it.
> Finally, modify it so that it uses a call to is_even to determine if its
>
On Thu, Aug 19, 2010 at 2:01 PM, Roelof Wobben wrote:
>
>
def is_odd(argument):
> uitkomst=is_even(argument)
> return uitkomst
>
> even=is_odd(1) ;
> if even==True :
> print "Even getal"
> if even==False:
> print "Oneven getal"
>
>
> But now I get this error message :
>
> return uitkomst
On Thu, Aug 19, 2010 at 3:01 PM, Roelof Wobben wrote:
> Hello,
>
> I have this exercise:
>
>
> Now write the function is_odd(n) that returns True when n is odd and
> Falseotherwise. Include doctests for this function as you write it.
> Finally, modify it so that it uses a call to is_even to det
Hello,
I have this exercise:
Now write the function is_odd(n) that returns True when n is odd and False
otherwise. Include doctests for this function as you write it.
Finally, modify it so that it uses a call to is_even to determine if its
argument is an odd integer.
So I thought of
(You top-posted, so now I have to delete the older part)
Vince Spicer wrote:
Hey you can use list comprehension here
age_dict = { 'pete': 42, 'ann': 25, 'carl': 30, 'amanda': 64 }
you can create a dict from a list of tuples and you can access the dict as
a
list of tuples by accessing its items
On Fri, 20 Aug 2010 01:40:54 am Wayne Werner wrote:
> > age_dict = dict([(key.upper(), value) for key,value in
> > age_dict.items()])
>
> This is a bad place to use a list comprehension. This will create a
> list of values first and then create a dict from that list, so now
> you have a list float
On Thu, Aug 19, 2010 at 8:21 PM, Pete wrote:
> Hi,
>
> I've been reading up on list comprehensions lately, all userful and
> powerful stuff - trying to wrap my brain around it :)
>
> As the examples all seem to relate to lists, I was wondering if there is an
> elegant similar way to apply a funct
On Thu, Aug 19, 2010 at 10:02 AM, Vince Spicer wrote:
> Hey you can use list comprehension here
>
>
> age_dict = { 'pete': 42, 'ann': 25, 'carl': 30, 'amanda': 64 }
>
> you can create a dict from a list of tuples and you can access the dict as
> a
> list of tuples by accessing its items
>
> Examp
Pete wrote:
> Hi,
>
> I've been reading up on list comprehensions lately, all userful and
> powerful stuff - trying to wrap my brain around it :)
>
> As the examples all seem to relate to lists, I was wondering if there is
> an elegant similar way to apply a function to all keys in a dictionary?
Hey you can use list comprehension here
age_dict = { 'pete': 42, 'ann': 25, 'carl': 30, 'amanda': 64 }
you can create a dict from a list of tuples and you can access the dict as
a
list of tuples by accessing its items
Example:
age_dict = dict([(key.upper(), value) for key,value in age_dict.item
Hi,
I've been reading up on list comprehensions lately, all userful and powerful
stuff - trying to wrap my brain around it :)
As the examples all seem to relate to lists, I was wondering if there is an
elegant similar way to apply a function to all keys in a dictionary?
(without looping over i
Thanks guys,
NamedTuple implementation is preety nice solution.
--nitin
On Thu, Aug 19, 2010 at 6:28 PM, Peter Otten <__pete...@web.de> wrote:
> Peter Otten wrote:
>
> > Nitin Das wrote:
> >
> >> class mymut(object):
> >>
> >> def __setattr__(self,k,v):
> >> if hasattr(self,k):
> >>
Hello All,
>> Please guide with the syntax.
>
> All beginners tutorials on the web teach the syntax of python.. I am
> unsure what your questions is.
My bad with code.
>
>> below is the existing program with Formula A (Mean). Formula B will be
>> Extrapolation,
>> also I have not been abl
"Roelof Wobben" wrote
I don't see a traceback only this output.
That looks about right to me, what did you expect to see that was
different?
regel 1
regel 2
script terminated.
=
I have learned to do one problem at the time so in mu o
Peter Otten wrote:
> Nitin Das wrote:
>
>> class mymut(object):
>>
>> def __setattr__(self,k,v):
>> if hasattr(self,k):
>> if self.__dict__.get(k) == None:
>> self.__dict__[k] = v
>> else:
>> raise TypeError("Cant Modify Attribute Value")
>
Hello,
I don't see a traceback only this output.
regel 1
regel 2
script terminated.
And the code I gave you was the whole code because Im still working on this one.
I have learned to do one problem at the time so in mu opion first make the part
which prints out 3 lines and
Nitin Das wrote:
> class mymut(object):
>
> def __setattr__(self,k,v):
> if hasattr(self,k):
> if self.__dict__.get(k) == None:
> self.__dict__[k] = v
> else:
> raise TypeError("Cant Modify Attribute Value")
> else:
> raise T
Can you copy and paste the exact error message you receive in the traceback
when you run your program. Also, copy the complete program here since it is
only a handful of lines
On Thu, Aug 19, 2010 at 7:31 AM, Roelof Wobben wrote:
> Hello,
>
> I follow the online book " How to think like a comp
On Thu, 19 Aug 2010 01:24:11 pm Nitin Das wrote:
> Hello,
>
> Can somebody help me how to make immutable objects in python. I
> have seen overriding the __new__, __setattr__ methods.. but not
> comfortable with how to use them to make the object immutable.
>
> thanks in advance
> --nitin
I ha
I am out of the office until 09/07/2010.
I will respond to your message when I return.
Note: This is an automated response to your message "Tutor Digest, Vol 78,
Issue 83" sent on 8/19/10 3:00:03.
This is the only notification you will receive while this person is away.
*IMPORTANT NOTICE: Th
Hello,
I follow the online book " How to think like a computer scientist".
But now I have a problem with a exercise.
This is not homework.
The exercise is :
Using a text editor, create a Python script named tryme3.py . Write a function
in this file called nine_lines that uses three
"Nitin Das" wrote
class mymut(object):
def __setattr__(self,k,v):
if hasattr(self,k):
if self.__dict__.get(k) == None:
self.__dict__[k] = v
Do you need to look up the dict?
Surely you could just use
if self.k is None
self.k = v
which looks a lot simpler to
26 matches
Mail list logo