0

* Python Code Challenge *

A question was unanswered for 16hrs. I tried it and am curious how the more experienced Python programmers in the community would handle the problem. I learn alot from seeing how people approach problems differently The task: Write a function that takes in an array of integers and returns the missing numbers. Needs to work with an array of any length. Any starting point. Any Ending point. Example: [11,5,15,7] Return: [6,8,9,10,12,13,14] Mine: https://code.sololearn.com/c2x1dAXrEQOl/?ref=app

14th Apr 2017, 1:51 AM
LordHill
LordHill - avatar
6 Respuestas
+ 4
Here's the code that I would use for this function https://code.sololearn.com/cctOQ50jxBjQ I just found the maximum and minimum in the input and then used the range to make a list comprehension for the integers that weren't found in the input.
14th Apr 2017, 3:41 AM
Roy Stewart
Roy Stewart - avatar
+ 3
"There should be one-- and preferably only one --obvious way to do it." - The Zen of Python This problem beautifully illustrates the line above, as my code would have looked exactly like Roy's.
14th Apr 2017, 6:09 PM
Tob
Tob - avatar
+ 1
Thanks Leaky Egg! I always love random challenges like this,especially when I get to see how other people solve the same problem in different ways.
14th Apr 2017, 3:50 AM
Roy Stewart
Roy Stewart - avatar
0
Excellent Roy. Works great! List Comprehension just made my list of things to study up on.
14th Apr 2017, 3:35 AM
LordHill
LordHill - avatar
0
of course there "should" only be 1 way. This is the point. we are here to learn and by having this challenge, I figured out a way to make it happen, then I saw Roy's way which lead me to list comprehension studys. After a bit more learning, My code will look very similar as well I am sure
14th Apr 2017, 6:15 PM
LordHill
LordHill - avatar
0
Thanks Roy. Seeing your code last night got me reading about list comprehension. after a couple minutes of reading, I wrote this def check(x): low=min(x) hi=max(x) myList=[i for i in range(low,hi) if i not in x] return myList Looking back at yours, 1 minor thing I can improve. Now, to practice it until it sticks.
14th Apr 2017, 9:52 PM
LordHill
LordHill - avatar