How to get the first value in the list

  obj = ['Execute', 'execute', 'VERB']

  if obj is not None:
        for token in obj :

how to get the first element using Python?

>Solution :

In Python, you cannot index into a set – these data structures are unordered and unindexed.

If you really insist on having obj be a set, you could do something like the following:

if "Execute" in obj:

However, this isn’t really a great way to manage this problem. The code snippet in your question suggests you want a way to store your data that is indexable. I would suggest a list:

obj = ['Execute', 'execute', 'VERB']  ## this is not a set
first_element = obj[0]
print(first_element) ## this will print 'Execute'

Leave a Reply