I have a an string and I need to get it into a format where I can iterate trough it:
[["","","",""],["","2","",""],["","","",""],["2","","",""]]
Can anyone help.
I have a an string and I need to get it into a format where I can iterate trough it:
[["","","",""],["","2","",""],["","","",""],["2","","",""]]
Can anyone help.
 
    
     
    
    If you want to get the list inside that string, you can just use json to load its content:
import json
list_ = json.loads('[["","","",""],["","2","",""],["","","",""],["2","","",""]]')
And then you can iterate over list_ as you please
 
    
    I am not sure what your asking exactly, but if you want to find the index in which "2" is located you can do this, otherwise pls elaborate:
storeString = [["","","",""],["","2","",""],["","","",""],["2","","",""]]
for i in storeString:
   if "2" in i:
     print(i.index("2"))
 
    
    I think the easiest way you can do it is:
my_list = [["", "", "", ""], ["", "2", "", ""], ["", "", "", ""], ["2", "", "", ""]]
my_new_list = []
for a_list in my_list:
    my_new_list.extend(a_list)
for item in my_new_list:
    print(item)
And the output will be:
2
2
You can iterate the list and use append instead of using extend:
my_list = [["", "", "", ""], ["", "2", "", ""], ["", "", "", ""], ["2", "", "", ""]]
my_new_list = []
for a_list in my_list:
    for item in a_list:
        my_new_list.append(item)
for item in my_new_list:
    print(item)
And the output will be the same.
And as The Zach Man mentioned, you can see more examples here (How to make a flat list out of list of lists?)
