0

I have the following list:

item = [['01jan.jpg', 'Cluny', 'Tres Riches Heures', 'January'],
        ['02feb.jpg', 'Cluny', 'Tres Riches Heures', 'February']]

and want to extract the first entry and change the .jpg to .png:

x = item[0][0]    print(x)  # gives '01jan.jpg'
y = slice(x[:-4]) print(y)  # gives 'slice(None, '01jan', None)'

and I can't get the middle term out because slice object is not iterable. How do I get '01jan' as a variable? Other items have varying names but all have the same .jpg so I want to slice off the back of the first item.

martineau
  • 119,623
  • 25
  • 170
  • 301
was698002
  • 1
  • 4

1 Answers1

0

What is wrong with just running x[:-4] without slice? That will get you 01jan. The other way of doing it is x[slice(-4)] but nobody uses this notation.

rudolfovic
  • 3,163
  • 2
  • 14
  • 38