What can be the most efficient way to remove first 10 elements from tuple?(every elements) [closed]

THE PROBLEM

Hi, I am currently learning python and opencv. I want to get only name of the dog species from the above pic, which removing the first 10 strings and numbers after the dog species.

For example:

[('n00000000-Maltese_dog', 252')] to 'Maltese_dog'.

I would appreciated if you can provide me any information of removing 'n' elements from tuple, or any help.

Thank you! Hope yall have a great day


Solution 1:

Don't think of it in terms of removing items, think of extracting the data you want.

For each tuple, t, in the list take the first item t[0] and then take a slice of the string t[0][10:]. You can use a list comprehension to make a new list of all the strings:

l = [
    ('n00000000-Maltese_dog', '252'),
    ('n10030000-Australian terrier', '252')
]

[t[0][10:] for t in l]
# ['Maltese_dog', 'Australian terrier']