+ 1

How can i make a function that takes two inputs lets say a certain number and an array of numbers and i want the function to return the remainders of dividing the number by the numbers in the array?

29th Mar 2017, 5:41 PM
Penny Jacobs
Penny Jacobs - avatar
4 Antworten
+ 5
No problem, don't forget to like the code if it helped you :D
30th Mar 2017, 6:19 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 4
It's a one-liner, see for yourself ;) https://code.sololearn.com/cSBRlV1pDLo4/?ref=app
29th Mar 2017, 8:14 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 2
An alternative would be to use the built-in map function. map(lambda x: number % x, array) I do not know which solution is better. Kuba's looks more Pythonic - I personally find mine more intuitive. Anyway, in most cases I'd let the rem function return the generator or map object and make the conversion to list only when necessary (does not matter in this case though).
30th Mar 2017, 7:27 PM
Tob
Tob - avatar
+ 1
Thank you
30th Mar 2017, 5:21 PM
Penny Jacobs
Penny Jacobs - avatar