So, your error is that instead of simply adding your latitute to the list, you are iterating over each character of the latitude, as a string, and adding that character to a list.
result=[]
for value in response_i['objcontent'][0]['rowvalues']:
lat = value[0]
print(lat)
result.append(float(lat))
print (result)
Besides that, using range(len(...))) is the way things have to be done in almost all modern languages, because they either don't implement a "for ...each" or do it in an incomplete or faulty way.
In Python, since the beginning it is a given that whenever one wants a for iteration he wants to get the items of a sequence, not its indices (for posterior retrieval of the indices). Some auxiliar built-ins come in to play to ensure you just interate the sequence: zip to mix one or more sequences, and enumerate to yield the indices as well if you need them.
Answer from jsbueno on Stack Overflowpython - Create a list of floats with only a specific decimal [0.0, 0.7, 1.0, 1.7, 2.0, 2.7, 3.0, 3.7, 4.0, 4.7, ...etc] - Stack Overflow
Python 3: how to create list out of float numbers? - Stack Overflow
Python creating a lists of lists of floats from a single list of strings - Stack Overflow
python - How do I convert all of the items in a list to floats? - Stack Overflow
Here ya go:
[[int(y) for y in x.split(",")] for x in objectListData]
output:
[[1, 2, 3, 4], [5, 6, 7, 8], [9, 0, 0, 7], [5, 4, 3, 2], [2, 3, 3, 3], [2, 2, 3, 3]]
or, if you want floats:
[[float(y) for y in x.split(",")] for x in objectListData]
output:
[[1.0, 2.0, 3.0, 4.0], [5.0, 6.0, 7.0, 8.0], [9.0, 0.0, 0.0, 7.0], [5.0, 4.0, 3.0, 2.0], [2.0, 3.0, 3.0, 3.0], [2.0, 2.0, 3.0, 3.0]]
The problem is that your inner lists are references to one single list and not individual lists.
>>> objectListDataFloats = [[0] * len(objectListData[0].split(', '))] * len(objectListData)
>>> objectListDataFloats
[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
>>> id(objectListDataFloats[0]) == id(objectListDataFloats[1])
True
After you fix that, you need to iterate from the starting index of 0, since the lists in Python start their index from 0.
for count in range(len(objectListData)):
for ii in range(len(objectListData[count].split(', '))):
objectListDataFloats[count][ii] = float(objectListData[count].split(', ')[ii])
>>> objectListDataFloats
[[1.0, 2.0, 3.0, 4.0], [5.0, 6.0, 7.0, 8.0], [9.0, 0.0, 0.0, 7.0], [5.0, 4.0, 3.0, 2.0], [2.0, 3.0, 3.0, 3.0], [2.0, 2.0, 3.0, 3.0]]
To completely do away with the initial initialization of the list with zeroes, you could also just build the list as you go along, something like
>>> objectListDataFloats = []
>>> for elem in objectListData:
test_list = []
for val in elem.split(','):
test_list.append(float(val))
objectListDataFloats.append(test_list)
>>> objectListDataFloats
[[1.0, 2.0, 3.0, 4.0], [5.0, 6.0, 7.0, 8.0], [9.0, 0.0, 0.0, 7.0], [5.0, 4.0, 3.0, 2.0], [2.0, 3.0, 3.0, 3.0], [2.0, 2.0, 3.0, 3.0]]
You don't need to iterate over the list or a string by using indices, you can just iterate over the list like in the above example.
Reduced Solution -
You could just reduce the whole solution to the following though (Change int to float if you require floating point numbers)
>>> objectListData = ["1, 2, 3, 4", "5, 6, 7, 8", "9, 0, 0, 7", "5, 4, 3, 2", "2, 3, 3, 3", "2, 2, 3, 3"]
>>> [map(int, elem.split(',')) for elem in objectListData]
[[1, 2, 3, 4], [5, 6, 7, 8], [9, 0, 0, 7], [5, 4, 3, 2], [2, 3, 3, 3], [2, 2, 3, 3]]
Use with AI[float(i) for i in lst]
to be precise, it creates a new list with float values. Unlike the map approach it will work in py3k.
map(float, mylist) should do it.
(In Python 3, map ceases to return a list object, so if you want a new list and not just something to iterate over, you either need list(map(float, mylist) - or use SilentGhost's answer which arguably is more pythonic.)