How to make dynamic array with different values ​​in Python

I have lines in a file like:

20040701         0  20040701         0      1  52.965366  61.777687  57.540783

      

I want to put this in a dynamic array if possible?

Sort of

try:
    clients = [
        (107, "Ella", "Fitzgerald"),
        (108, "Louis", "Armstrong"),
        (109, "Miles", "Davis")
        ]
    cur.executemany("INSERT INTO clients (id, firstname, lastname) \
        VALUES (?, ?, ?)", clients )
except:
    pass

      

0


a source to share


3 answers


You can easily compose a list of numbers from a string like your first example, simply [float(x) for x in thestring.split()]

- but "Something Like" doesn't look like the first example and doesn't seem to have anything to do with the Subject question.



+2


a source


In [1]: s = "20040701 0 20040701 0 1 52.965366 61.777687 57.540783"

In [2]: strings = s.split(" ")

In [3]: strings
Out[3]: ['20040701', '0', '20040701', '0', '1', '52.965366', '61.777687', '57.540783']

In [6]: tuple(strings)
Out[6]: ('20040701', '0', '20040701', '0', '1', '52.965366', '61.777687', '57.540783')

      



Is this what you are looking for? I'm not sure about your question.

+2


a source


From my reading for your question, I think you need something like:

rows = [map (Decimal, x.split ('')) for x in lines]
+1


a source







All Articles