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