This question already has an answer here:
For instance, I have a string that splits into 3 parts but I need just the first and third parts.
one, two, three = '1 2 3'.split()
After the above line, I would have to execute a "del" to remove it from variable list.
del(two)
Is there a way I can discard "two" immediately? Like"
one, _, three = '1 2 3'.split()
Additionally, this is not a question about language semantics which has been answered in the following question.
What is the purpose of the single underscore "_" variable in Python?
This is a question if Python runtime has that feature to remove the variable automatically.
</div>
If this is your actual case you can do one,_,three = '1 2 3'.split()
Whereas, an alternative would be one,three = '1 2 3'.split()[::2]
, which gives only odd numbers, or skips the odd-indexed values.
But for a high index, such as 20, the only way to skip that would be to delete the element from the list(I believe), or do one,two,three ... _, twenty