Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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:
  print("Execute")

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'
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading