Split the texts in the array into words Python

Question:

Is there a way to split the text of each input in an array to words with a separator?
Example Input

tag_attribute = ['Content_ExportDate','Controller_SoftwareRevision','DataType_Owner']

With the separator as ‘_’, the expected printed result:

Tag: Content
Attribute: Exportdate
Tag: Controller
Attribute: SoftwareRevision
Tag: DataType
Attribute: Owner

The ‘_’ is just an example I can think of for a separator, but I can work with any of other symbols. I just need to find a way to have the input in an array as two separate inputs

Asked By: Quan Hoang Nguyen

||

Answers:

You can use this example it will generate you the output that you want

for tag, att in [x.split("_") for x in tag_attribute]:
  print(f"Tag: {tag}")
  print(f"Attribute: {att}")

Answered By: tomerar
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.