The 365 Data Science team is proud to invite you to our own community forum. A very well built system to support your queries, questions and give the chance to show your knowledge and help others in their path of becoming Data Science specialists.
Ask
Anybody can ask a question
Answer
Anybody can answer
Vote
The best answers are voted up and moderated by our team

Feedback to Python Bootcamp further exercises (List Comprehensions)

Feedback to Python Bootcamp further exercises (List Comprehensions)

Super Learner
0
Votes
0
Answer

There are two things I think are “wrong” with two of the answers. Not “wrong” as in they don’t work, but wrong as in “poor answers given the target audience”.
Answer 18. Here a completely new (to most people) syntax is introduced with no explanation whatsoever. Prior to this, all the work has been with the long form layout – which is easy to read and easy to understand for novices. Suddenly introducing “divisors = [i for i in range(1,num + 1) if num%i ==0]” with no discussion and no pointers for further learning is a bit of a tough ask. I had only seen the compact form as it was used in some of the StackOverflow questions I’d looked at which doing other questions.
Answer 20. It took me a few moments to work out how the given answer works. This is another example where the given answer will work, but it can be inefficient. A quick check shows that for small intervals of start-end then it’s more efficient than the “traditional” approach*, but if the interval is not small relative to the scale of starting number, then it takes many more divisions. For example, with a range from 882 to 1000 the given solution is more efficient, but from 881 to 1000 is less efficient – and the change in iterations needed with cahnge in range selected is surprisingly large.
* Start at 2 with empty list, if number is not divisible by any member of list then add to list. So instead of testing division by 2,3,4,5,6,7,8,9,10,11,… you only test by division with 2,3,5,7,11,…

 

EDIT: after a bit more looking around, I see answer 18 is using a list comprehension. Surely something like this is deserving of it’s own section in the course ?

No answers so far.