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 insert every string character to two dimensional array

I’ve made two dimensional array

rows, columns = (5, 4)
table = [["" for i in range(columns)] for j in range(rows)]

now I want to insert every string character to it

string = "aaa bb cccc d eee"

I want this output :
[[‘a’, ‘a’, ‘a’, ”], [‘b’, ‘b’, ”, ‘c’], [‘c’, ‘c’, ‘c’, ”], [‘d’, ”, ‘e’, ‘e’], [‘e’, ”, ”, ”]]

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

I tried something like this in many ways but it throws an error.

 for i in range(len(string)):
        table[columns][rows] = string[i]

>Solution :

for i in range(len(s)):
    lis[i // columns][i % columns] = s[i]
print(lis)
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