-1

I have a 2d List

a= [['Turn', 'the', 'light', 'out', 'now'], ['Now', ',', 'I', 'll', 'take', 'you', 'by', 'the', 'hand'], ['Hand', 'you', 'anoth', 'drink'], ['Drink', 'it', 'if', 'you', 'can'], ['Can', 'you', 'spend', 'a', 'littl', 'time'], ['Time', 'is', 'slip', 'away'], ['Away', 'from', 'us', ',', 'stay'], ['Stay', 'with', 'me', 'I', 'can', 'make'], ['Make', 'you', 'glad', 'you', 'came']]

Is there an easy way to get a range of values from this list?

if I write:

print a[0][0] 

I get 'Turn', but is there a way to slice multiple things out of the list and make a new list? If I have a value i=0 and n=2 I am looking to make a new list that starts at a=[i][n] and makes a new list with the list items on either side of that index.

Thanks for the help

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
English Grad
  • 1,365
  • 5
  • 21
  • 40

1 Answers1

0

Maybe you mean

print a[0][0:2]

or

print [d[0] for d in a]
kharandziuk
  • 12,020
  • 17
  • 63
  • 121