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0 0 8 4 4 4 4 4 4 4 8 0 0 4 4\n', '4 4 0 0 6 4 4 4 4 4 4 4 6 0 0 4 4\n', '4 4 0 0 8 4 4 4 4 4 4 4 8 0 0 4 4\n', '4 4 0 0 8 4 4 4 4 4 4 4 8 0 0 4 4\n', '4 4 0 0 6 8 9 7 4 7 9 8 6 0 0 4 4\n', '4 4 0 0 0 0 0 0 4 0 0 0 0 0 0 4 4\n', '4 4 4 0 0 0 0 0 4 0 0 0 0 0 4 4 4\n', '4 4 4 4 0 0 0 0 4 0 0 0 0 4 4 4 4\n', '4 4 4 4 4 4 0 0 4 0 0 4 4 4 4 4 4\n', '4 4 4 4 4 4 0 0 4 0 0 4 4 4 4 4 4\n', '4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4\n', '4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4\n', '4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4\n', '4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4\n', '4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4\n', '4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4']
l1 = []
> for j in s:
l1.append([i for i in j if not i.isspace()])
l1
[
['4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4'], ['4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4'], ['4', '4', '4', '4', '0', '0', '0', '0', '0', '0', '0', '0', '0', '4', '4', '4', '4'], ['4', '4', '4', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '4', '4', '4'], ['4', '4', '0', '0', '6', '8', '8', '8', '6', '8', '8', '8', '6', '0', '0', '4', '4'], ['4', '4', '0', '0', '8', '4', '4', '4', '4', '4', '4', '4', '8', '0', '0', '4', '4'], ['4', '4', '0', '0', '8', '4', '4', '4', '4', '4', '4', '4', '8', '0', '0', '4', '4'], ['4', '4', '0', '0', '6', '4', '4', '4', '4', '4', '4', '4', '6', '0', '0', '4', '4'], ['4', '4', '0', '0', '8', '4', '4', '4', '4', '4', '4', '4', '8', '0', '0', '4', '4'], ['4', '4', '0', '0', '8', '4', '4', '4', '4', '4', '4', '4', '8', '0', '0', '4', '4'], ['4', '4', '0', '0', '6', '8', '9', '7', '4', '7', '9', '8', '6', '0', '0', '4', '4'], ['4', '4', '0', '0', '0', '0', '0', '0', '4', '0', '0', '0', '0', '0', '0', '4', '4'], ['4', '4', '4', '0', '0', '0', '0', '0', '4', '0', '0', '0', '0', '0', '4', '4', '4'], ['4', '4', '4', '4', '0', '0', '0', '0', '4', '0', '0', '0', '0', '4', '4', '4', '4'], ['4', '4', '4', '4', '4', '4', '0', '0', '4', '0', '0', '4', '4', '4', '4', '4', '4'], ['4', '4', '4', '4', '4', '4', '0', '0', '4', '0', '0', '4', '4', '4', '4', '4', '4'], ['4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4'], ['4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4'], ['4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4'], ['4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4'], ['4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4'], ['4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4']]
l2 = []
> for j in s:
l2.append(j.split())
l2
[
['4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4'], ['4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4'], ['4', '4', '4', '4', '0', '0', '0', '0', '0', '0', '0', '0', '0', '4', '4', '4', '4'], ['4', '4', '4', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '4', '4', '4'], ['4', '4', '0', '0', '6', '8', '8', '8', '6', '8', '8', '8', '6', '0', '0', '4', '4'], ['4', '4', '0', '0', '8', '4', '4', '4', '4', '4', '4', '4', '8', '0', '0', '4', '4'], ['4', '4', '0', '0', '8', '4', '4', '4', '4', '4', '4', '4', '8', '0', '0', '4', '4'], ['4', '4', '0', '0', '6', '4', '4', '4', '4', '4', '4', '4', '6', '0', '0', '4', '4'], ['4', '4', '0', '0', '8', '4', '4', '4', '4', '4', '4', '4', '8', '0', '0', '4', '4'], ['4', '4', '0', '0', '8', '4', '4', '4', '4', '4', '4', '4', '8', '0', '0', '4', '4'], ['4', '4', '0', '0', '6', '8', '9', '7', '4', '7', '9', '8', '6', '0', '0', '4', '4'], ['4', '4', '0', '0', '0', '0', '0', '0', '4', '0', '0', '0', '0', '0', '0', '4', '4'], ['4', '4', '4', '0', '0', '0', '0', '0', '4', '0', '0', '0', '0', '0', '4', '4', '4'], ['4', '4', '4', '4', '0', '0', '0', '0', '4', '0', '0', '0', '0', '4', '4', '4', '4'], ['4', '4', '4', '4', '4', '4', '0', '0', '4', '0', '0', '4', '4', '4', '4', '4', '4'], ['4', '4', '4', '4', '4', '4', '0', '0', '4', '0', '0', '4', '4', '4', '4', '4', '4'], ['4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4'], ['4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4'], ['4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4'], ['4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4'], ['4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4'], ['4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4', '4']]
l3 = []
> for j in s:
l3.append([int(i) for i in j if not i.isspace()])
l3
[
[4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4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[4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]][/code:1l52u2pk]
Assuming that you don't want the spaces in the final data structure, and you want numerical values instead of characters, and that you may want to use Construct's array object, I made a simple .cap that demonstrates how you can load the data file into both a 2D python list and a 2D Construct array.
http://dl.dropbox.com/u/5868916/grid.zip
The text file should be in the same folder as the .cap in it's current form, is all.