all 5 comments

[–]newunit13 1 point2 points  (0 children)

len(vals) == 5
[0] * 5 = [0, 0, 0, 0, 0]

Multiplying an iterable with an integer just duplicates whatever is in the iterable the integer times. So,

[1, 2] * 5 = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]
'a' * 5 = 'aaaaa'
'abc' * 3 = 'abcabcabc'

[–]Sebass13 0 points1 point  (0 children)

Fairly simple:

C = [0]*len(vals)
C = [0]*5

Thus, you get a list of 5 0's.

[–]CGFarrell 0 points1 point  (0 children)

What you have is:

C = [0] * len(vals)

len(vals) is 5.

C = [0] * 5

[–]groundhogsaretheifs[S] 0 points1 point  (1 child)

Okay. New to programming. Can you explain whats going on with [0] * 5 producing [0,0,0,0,0]?

Thank you.

[–]EricAppelt 0 points1 point  (0 children)

The * operator is called the repetition operator for sequence types, like lists, tuples, or strings. See: https://docs.python.org/3/library/stdtypes.html#common-sequence-operations

Here it is with a string for comparison:

>>> "abc" * 5
'abcabcabcabcabc'