Jun-16-2019, 10:27 AM
(Jun-16-2019, 10:05 AM)noisefloor Wrote: Hi,
first of all: your post would be _much_ more readable if you would write words correctly in upper and lower case and especially would use punctuation.
in Python you can iterate directly over list and tuples, as the are iterable. So no need forrange
orlen
or anything. Just dofor item in iterable:
.
I do not really understand what the final output should be. You a list of three tuples and want to get ... what? The example in your 2nd code block doesn't make to much sense... Do you want a dict for each item in the list, which would be three dicts as per your example. Or do you want to get a dict of dicts?
And why to do need a dict at all? Your input, the list of tuples, is already ordered, isn't it?
And did you check the documentation of your data source if this isn't able already to provide a dict instead of a list?
Regards, noisefloor
Hey, i want it to show as json by list, like this :
[(event_id :10, cp_ids : 'cp5', event_type: 'ERROR', start_ts : 201905021800.0, end_ts : 201905021900.0, record: 1.2, 1.5]) }, event_id :11, cp_ids: 'cp3', event_type : 'ERROR', start_ts: 201905021800.0, end_ts: 201905021900.0, record: 1.2, 1.5 }, event_id:12, cp_ids:'cp7', 'cp4', event_type:'ERROR', start_ts: 201905021800.0, end_ts : 201905021900.0, record: 1.2, 1.5 }Even if i do the for i in, it does work but only for one list. the question is how do i make it
go throw all list ( if there is 3 lists like here or even 20 lists)
This is my code :
records = { "event_id": nvm[0][0] , "cp_ids": nvm[0][1] , "event_type": nvm[0][2] , "start_ts": nvm[0][3] , "end_ts": nvm[0][4] , "record": nvm[0][5] }How can i make the nvm[0][0] = nvm[n][0] to know to iterate on all list ?
Im new to python