-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
  • 963,270
  • 265
  • 3,804
  • 3,187
English Grad
  • 1,275
  • 4
  • 20
  • 39

1 Answers1

0

Maybe you mean

print a[0][0:2]

or

print [d[0] for d in a]
kharandziuk
  • 10,580
  • 11
  • 55
  • 108