0

I'm trying to loop around a structured string or list to extract data but I always end up with Type Error or Value error. I tried to convert it to JSON but with the same results. Here is the string:

I want to extract the corresponding data to the values untagged_vlan, tagged_vlan, port_name and port_number. Is there any way to convert this string into slices so I can loop around them and extract the required data?

Thanks in advance

[[{'untagged_vlan': '101', 'tagged_vlan': '1000', 'port_name': '"01-01-140"', 'port_no': '1'}, {'untagged_vlan': '101', 'tagged_vlan': '1000', 'port_name': '"02-01-142"', 'port_no': '2'}, {'untagged_vlan': '101', 'tagged_vlan': '1000', 'port_name': '"03-01-144"', 'port_no': '3'}, {'untagged_vlan': '101', 'tagged_vlan': '1000', 'port_name': '"04-01-146"', 'port_no': '4'}, {'untagged_vlan': '101', 'tagged_vlan': '1000', 'port_name': '"05-01-148"', 'port_no': '5'}, {'untagged_vlan': '101', 'tagged_vlan': '1000', 'port_name': '"06-01-150"', 'port_no': '6'}, {'untagged_vlan': '101', 'tagged_vlan': '1000', 'port_name': '"07-01-151"', 'port_no': '7'}, {'untagged_vlan': '101', 'tagged_vlan': '1000', 'port_name': '"08-01-152"', 'port_no': '8'}, {'untagged_vlan': '101', 'tagged_vlan': '1000', 'port_name': '"09-01-153"', 'port_no': '9'}, {'untagged_vlan': '101', 'tagged_vlan': '1000', 'port_name': '"10-01-155"', 'port_no': '10'}]]

1 Answer 1

3
data = [[{'untagged_vlan': '101', 'tagged_vlan': '1000', 'port_name': '"01-01-140"', 'port_no': '1'}, {'untagged_vlan': '101', 'tagged_vlan': '1000', 'port_name': '"02-01-142"', 'port_no': '2'}, {'untagged_vlan': '101', 'tagged_vlan': '1000', 'port_name': '"03-01-144"', 'port_no': '3'}, {'untagged_vlan': '101', 'tagged_vlan': '1000', 'port_name': '"04-01-146"', 'port_no': '4'}, {'untagged_vlan': '101', 'tagged_vlan': '1000', 'port_name': '"05-01-148"', 'port_no': '5'}, {'untagged_vlan': '101', 'tagged_vlan': '1000', 'port_name': '"06-01-150"', 'port_no': '6'}, {'untagged_vlan': '101', 'tagged_vlan': '1000', 'port_name': '"07-01-151"', 'port_no': '7'}, {'untagged_vlan': '101', 'tagged_vlan': '1000', 'port_name': '"08-01-152"', 'port_no': '8'}, {'untagged_vlan': '101', 'tagged_vlan': '1000', 'port_name': '"09-01-153"', 'port_no': '9'}, {'untagged_vlan': '101', 'tagged_vlan': '1000', 'port_name': '"10-01-155"', 'port_no': '10'}]]
    
extracted = [item.values() for item in data[0]]

print(extracted)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.