Re: [Tutor] python question

2019-08-18 Thread Steven D'Aprano
On Sun, Aug 18, 2019 at 12:35:52PM +0800, Thejal Ramesh wrote:
> Hi, i have a question regarding this question. I'm not quite sure what the
> question is asking.

Ask your tutor. We can help you with learning Python the programming 
language, not graph theory.

https://en.wikipedia.org/wiki/Graph_theory


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


Re: [Tutor] python question

2019-08-18 Thread Alan Gauld via Tutor
On 18/08/2019 05:35, Thejal Ramesh wrote:
> Hi, i have a question regarding this question. I'm not quite sure what the
> question is asking.

> Part A: Popular (1.5 Marks)
>  Write a function popular(graph list, n) that returns a list of people who
> have at least n friends. Each person is identified by the number of their
> vertex.

>  Examples clayton_list = [ [1,2,3], [0,3], [0,4], [0,1], [2] ]
> The example graph clayton list is provided for illustrative purpose. Your
> implemented function must be able to handle arbitrary graphs in list form
> . a) Calling popular(clayton list,2) returns [0,1,2,3].
>  b) Calling popular(clayton list,3) returns [0]
> . c) Calling popular(clayton list,0) returns [0,1,2,3,4].

The question is asking you to write a function that returns the
indexes of the elements in the input list of length equal to or
greater than the input value.

Looking at the sample data, clayton_list
a) returns all but the last item because only the last item has less
   than 2 members
b) returns only the first item because only the first item contains
   3 or more members
c) returns all items because all have zero or more members.

What the question does not specify is what the function should return
if there are no members found. I would assume an empty list...

To do this you will need some kind of loop and a test and build a list.
If you know about list comprehensions that might be one option. (If you
don't, use a normal for loop)

HTH
-- 
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


[Tutor] python question

2019-08-18 Thread Thejal Ramesh
Hi, i have a question regarding this question. I'm not quite sure what the
question is asking.
Part A: Popular (1.5 Marks)
 Write a function popular(graph list, n) that returns a list of people who
have at least n friends. Each person is identified by the number of their
vertex.
Input: a nested list graph list that represents a graph as an adjacency
list, that models the friendships at Monash; and a non-negative integer n.
Output: a list of integers, where each integer is a person with at least n
friends. If no person has at least n friends, return an empty list. The
list may be in any order.
 Examples clayton_list = [ [1,2,3], [0,3], [0,4], [0,1], [2] ]
The example graph clayton list is provided for illustrative purpose. Your
implemented function must be able to handle arbitrary graphs in list form
. a) Calling popular(clayton list,2) returns [0,1,2,3].
 b) Calling popular(clayton list,3) returns [0]
. c) Calling popular(clayton list,0) returns [0,1,2,3,4].
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor