Re: [Tutor] __getitem__

2016-11-24 Thread monik...@netzero.net
Hi:
Thank you very much for ALL your postings. They help a lot and now things make 
sense.
Thank you
Monika

-- Original Message --
From: Alan Gauld via Tutor 
To: tutor@python.org
Subject: Re: [Tutor] __getitem__
Date: Wed, 23 Nov 2016 22:25:08 +

On 23/11/16 12:25, monik...@netzero.net wrote:

> I have two questions in regards to below code:
> 1. largest is a list, not a list of lists. 
> [('deit', 4), ('acer', 3), ('aceilmr', 2), ('arst', 2)]
> so why when I do largest[0] I get the whole list again, 

I don't know you will need to show us some real code.
Ideally input at the >>> prompt.

> 2. largest = [sorted(analist, key=lambda analist: analist[1], reverse=True)]
> brings back the same result as:
> largest = [sorted(analist, key=lambda d: d[1], reverse=True)]
> and the same result as:
> largest = [sorted(analist, key=lambda x: x[1], reverse=True)]

Yes because it doesn't matter what you call the parameter of the lambda,
it's like any other function:

def add2(x): return x+2

def add2(y): return y+2

def add2(z): return z+2

All of these functions are identical they always do the same
regardless of what you call the parameter. Remember a lambda
is just a shortcut for a function

key = lambda d: d[1]

is identical to

def key(d): return d[1]

and

key = lambda analist: analist[1]

is identical to

def key(analist): return analist[1]

Just like the add2() examples it doesn't matter what
name you use for the parameter.

> ...but where does it get the x, what is the value of x? 

See my other post about how sorted() works.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


3 Signs You May Have a Fatty Liver [Watch]
livecellresearch.com
http://thirdpartyoffers.netzero.net/TGL3241/58363984eaf793984277ast02duc
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Python code

2016-11-24 Thread urfa jamil
I need help to write a code for this problem.

Please help


Ask the user to enter a series of numbers. Stop reading numbers when they enter 
a negative number. Calculate the average of the numbers given not including the 
final negative number.

Question 9 options:



With best regards
urfa jamil
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python code

2016-11-24 Thread Alan Gauld via Tutor
On 24/11/16 23:14, urfa jamil wrote:
> I need help to write a code for this problem.
> 
> Please help

OK, But what exactly do you want help with? Have you written any code
yet? If so show us. Also if you get an error message post it.

> Ask the user to enter a series of numbers. 

Can you do this bit?
Can you get the user to enter a single number and store it?

> Stop reading numbers when they enter a negative number. 

Can you do this bit?


> Calculate the average of the numbers given 

Can you calculate the average of a collection of numbers?

> not including the final negative number.

Can you exclude the last element?

> Question 9 options:

No idea what that means!


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python code

2016-11-24 Thread Ben Finney
urfa jamil  writes:

> I need help to write a code for this problem.

We can help by discussing the solution you have written. Simply post a
reply, and include the program code you wrote for solving the problem.

> Please help

Note that “help” is not the same as “write the solution for me”. You
have to do the work yourself, and we can help by discussing what you've
done.

-- 
 \   “Try to learn something about everything and everything about |
  `\  something.” —Thomas Henry Huxley |
_o__)  |
Ben Finney

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor