-6

In Python I have a list: [11,42,122,1919, 17, 4] and want to calculate its modulo a number (e.g. 10) to give the result as a list: [1,2,2,9,7,4]

mfitzp
  • 15,275
  • 7
  • 50
  • 70
J.Doe
  • 281
  • 4
  • 12

2 Answers2

1

Even though it's a homework question, you can do it as:

[a%10 for a in l]

shivsn
  • 7,680
  • 1
  • 26
  • 33
SurDin
  • 3,281
  • 4
  • 26
  • 28
  • not sure he knows what that means, as per his last comment "I'm not a coder, so please just help me" – glls May 30 '16 at 09:32
0

You can also do it without list comprehension, like this:

    num_list = [11,42,122,1919, 17, 4]

    result = []
    for num in num_list:
        result.append(num%10)
    print(result)

    # Output
    [1, 2, 2, 9, 7, 4]

If you're new to python then this sort of structure with code is quite common to use.

RoadRunner
  • 25,803
  • 6
  • 42
  • 75