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

Python for loop items in single array

How can I convert incoming for loop items into a single array?

 for txn in txn_card:
        text = txn.text
        text = np.array([text])
        print(text)

output

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

>Solution :

With your ‘comment’, you may try something along the line of list comprehension

## define 'items'
#txn_card = ['item1', 'item2', 'item3']
##or
txn_card = [['item1'], ['item2'], ['item3']]

## Use a list comprehension to create the new array
#new_txn_card = np.array([item for item in txn_card])
new_txn_card = [item for item in txn_card]

## Print the new array
print(new_txn_card)
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