Just as you wrote it:

>>> matrix = [["str1", "str2"], ["str3"], ["str4", "str5"]]
>>> matrix
[['str1', 'str2'], ['str3'], ['str4', 'str5']]
>>> matrix[0][1]
'str2'
>>> matrix[0][1] += "someText"
>>> matrix
[['str1', 'str2someText'], ['str3'], ['str4', 'str5']]
>>> matrix[0].extend(["str6"])
>>> matrix[0]
['str1', 'str2someText', 'str6']

Just think about 2D matrix as list of the lists. Other operations also work fine, for example,

>>> matrix[0].append('value')
>>> matrix[0]
[0, 0, 0, 0, 0, 'value']
>>> matrix[0].pop()
'value'
>>> 
Answer from Klark on Stack Overflow
๐ŸŒ
Processing
py.processing.org โ€บ tutorials โ€บ 2dlists
Two-Dimensional Lists \ Tutorials
Python Mode for Processing extends the Processing Development Environment with the Python programming language.
๐ŸŒ
Snakify
snakify.org โ€บ two-dimensional lists (arrays)
Two-dimensional lists (arrays) - Learn Python 3 - Snakify
You can use nested generators to create two-dimensional arrays, placing the generator of the list which is a string, inside the generator of all the strings.
Discussions

2D array of lists in python - Stack Overflow
I am trying to create a 2d matrix so that each cell contains a list of strings. Matrix dimensions are known before the creation and I need to have access to any element from the beginning (not populating a matrix dynamically). I think some kind of pre-allocation of space is needed. ... btw, I think you should start with a basic python ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Strings in 2D lists in Python - Stack Overflow
This will be String type. You just change the representaion of the object 2019-05-28T11:49:30.707Z+00:00 ... And converting it to type list gives horrendous answer, I don't think it is achievable what the OP wants. 2019-05-28T11:54:41.32Z+00:00 ... this one actually worked but how do i make the lists ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
May 28, 2019
How do I merge a 2D array in Python into one string with List Comprehension? - Stack Overflow
I think he's talking about the ... way, not list-comprehension-based. 2008-10-29T04:11:55.777Z+00:00 ... Then, join to make it a string. ... I don't see a flatten function in itertools. I am using Python 2.4.2 2008-09-19T17:57:24.873Z+00:00 ... def convert2DArrtostring(ndArr): '''converts 2D array to string''' ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
convert a string 2d list back to 2d list in python - Stack Overflow
I just started playing around with python. I know that we can convert any list to a string using str() Like: >>> l = [[1,1] , [2,2] , [3,3]] >>> l [[1, 1], [2, 2], [3, 3]] >>> type(l) >>> str(l) '[[1, 1], [2, 2], [3, 3]]' >>> list_string = str(l) >>> list_string '[[1, 1], [2, 2], [3, 3]]' >>> type(list_string) Is there a way to convert list_string back to a 2d ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
Quora
quora.com โ€บ How-can-a-list-of-strings-be-stored-within-a-2D-array
How can a list of strings be stored within a 2D array? - Quora
Quora is a place to gain and share knowledge. It's a platform to ask questions and connect with people who contribute unique insights and quality answers.
๐ŸŒ
YouTube
youtube.com โ€บ watch
Using Strings with 2D Lists - YouTube
Recorded with http://screencast-o-matic.com
Published: December 13, 2016
๐ŸŒ
SourceTrail
sourcetrail.com โ€บ home โ€บ python โ€บ solved: how to make a 2d list of a list of strings
Solved: how to make a 2d list of a list of strings in Python - SourceTrail
September 11, 2023 - Additionally, we will explore related libraries and functions that can enhance your understanding and efficiency when working with Python. Creating a 2D list from a list of strings is a fairly common task in Python. This is especially true when processing and analyzing data from various sources like text files, databases, or even web sources.
Find elsewhere
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 59167546 โ€บ how-do-i-read-a-text-file-into-a-2d-list-of-strings-in-python
How do I read a text file into a 2D list of strings in Python - Stack Overflow
def readLevel(n): '''takes an integer as argument representing the level number and reads the appropriate game board file. Returns it as a 2D list of strings.''' file = open('./levels/ascii_level1.txt','r') level = [] for line in file: numString = line.split() level.append(numString) file.close() return level
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ storing and using data from a 2d string list
r/learnpython on Reddit: Storing and using data from a 2d string list
April 13, 2022 -

I am trying to take a string at a specific index and store it so I can manipulate it and then place it back into the 2d array in a different column. My question is regarding the where I actually try to store it.

table is a 2d array of strings here

for rowpos in range(maxnumofrows) : { stringtoparse = table[rowpos][0] }

the stringtoparse setting line is whats giving me errors. I'm normally a java user, but I need to use python here. Any obvious reason why it doesn't work? I tried using the str() method to copy the data of the position because I thought perhaps making a pointer to an index in a 2d array was not allowed in python or something, but that did not fix the issue and the syntax error still remains.

๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 59147199 โ€บ create-a-2d-string-array
python - Create a 2D String Array - Stack Overflow
I'm trying to create a simple 2D array of country names and capital cities. This was straightforward i Java, but I'm toiling in Python. I'd like something along the lines of: Scotland Edinburgh
๐ŸŒ
Python Pool
pythonpool.com โ€บ home โ€บ tutorials โ€บ python 2d lists: create, index, copy, flatten, and loop
Python 2d List: From Basic to Advance
July 14, 2026 - The official Python data structures tutorial explains list operations. A 2D list is not a special array type; it is a nested collection, and rows may even have different lengths unless your program enforces a rectangular shape.
๐ŸŒ
Profound Academy
profound.academy โ€บ python-introduction โ€บ 2d-lists-akMJGCqUglNeHMBStGJ6
2D lists โ€ข Introduction to Python
November 2, 2024 - Python lists can contain different types of elements. They can have integers, strings, floating-point numbers, etc.
Top answer
1 of 4
1

You can assign the 2D list (list is the term for an array used in Python):

data = [["a", "b", "c", "d"], ["e", "f", "g", "h"]]

Next you can loop through each list inside the data list and assign the new value to the original value in the list:

idx = 0
for x in data:
    data[idx] = "".join(x)
    idx += 1

This will return the required output.

Full Code:

data = [["a", "b", "c", "d"], ["e", "f", "g", "h"]]
idx = 0
for x in data:
    data[idx] = "".join(x)
    idx += 1

Test your code by adding the following two lines:

print(f'First value in list: {data[0]} and second value in list: {data[1]}')

Explanation:

data = [["a", "b", "c", "d"], ["e", "f", "g", "h"]]

The line of code above assigns the 2D list to a variable to be used on later.

idx = 0

The variable idx is used to assign the required value to each of the former values of the 2D list data. You can also assign each value to a separate list by using the .append method.

for x in data:

This loops through each value (or list) inside of the list data, using the variable x to be referenced as in the code. This can also be done using a while loop.

data[idx] = "".join(x)

This assigns the former value with the index of idx in the list with the new value. This uses the python .join method to connect the values in the list by a "".

To read more about the Python .join method visit:

https://www.w3schools.com/python/ref_string_join.asp

idx += 1

This is used to add 1 to the former value of idx so that it outputs the new index of the next value in the list used in the for loop.

Testing Your Code

print(f'First value in list: {data[0]} and second value in list: {data[1]}')

the above line of code is a simple formatted string that outputs the first data[0] and second data[1] values of the variable data.

I hope this helps you with your coding and understanding your code.

2 of 4
1

You can try:

>>> data = [["a", "b", "c", "d"], ["e", "f", "g", "h"]]
>>> ["".join(d) for d in data]
['abcd', 'efgh']
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python-using-2d-arrays-lists-the-right-way
Python | Using 2D arrays/lists the right way - GeeksforGeeks
First, the array arr is initialized using a 2D list comprehension, where each row is created as [0, 0, 0, 0, 0]. The entire array is created as a list of references to the same inner list, resulting in aliasing.
Published: June 20, 2024