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.

0

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.