0

I'm somewhat new to Python. I have the following python 2 code:

m = [1,1,7,7,0,0,0,0,1,6,6,9,7,9,2] randomDigs = m[6 - [3][0]: -1]

What is happening inside randomDigs? I get the following output:

[7, 0, 0, 0, 0, 1, 6, 6, 9, 7, 9]

Aran-Fey
  • 39,665
  • 11
  • 104
  • 149
user220188
  • 15
  • 2

1 Answers1

1

[3][0] is just a complicated way to write 3 (the first element in the list containing 3 as only element). so your code boils down to m[3:-1] which means: create a new list from m starting from the 3rd (note: list indices start at 0) element up to (and excluding) the last element.

this answer explains how list indexing and slicing works in great detail.

hiro protagonist
  • 44,693
  • 14
  • 86
  • 111