Converting file data to nested list

I have a string of numbers that I would like to convert to a nested list. So far, I have

 with open('lifedata.txt') as f:
    table_data = [ line.split() for line in f]
print(table_data)

If the text document consists of numbers ordered like this,

0000000 0010000 0001000 0111000 0000000 0000000

The code I have so far only creates a nested list that looks like, [['0000000'], ['0010000'], ['0001000'], ['0111000'], ['0000000'], ['0000000']]

But instead, I wanted it took be [[0,0,0,0,0,0,0],[],[]] and so on. I also do not know how to convert the string into an integer. I'm just very confused on how I should manipulate the original text document to do what I want it to.

Answers


This is what is happening:

>>> "0000000".split()
['0000000']

Instead, call int() on every character in each string:

[[int(c) for c in line.strip()] for line in f] 

Or, via map():

[list(map(int, line.strip())) for line in f]

Use this ,it will return a list of containing data from each line of txt.

open('lifedata.txt').readlines()

Need Your Help

why qtip tool tip is not showing pop up on first click ,from second click its showing the tool tip

javascript jquery ajax qtip

UPDATED Question :: its working from left click on the node ,inaddtion to that from the right click also it should work for us..on right click-->properties,pop shpuld be displyed on the actual nod...

Doesn't recognized obb file while run my corona application on android device

android debugging sdk corona apk-expansion-files

I'm building a game for mobile devices with corona sdk, it already run on iOS devices and now I want to install it on android device.