I'm using python and have the following dictionary:
{
'Measurement1': {
'point1': [['1.1', '1,2', '497.1937349917', '497.1937349917', '497.1937349917'],
['3.1', '1,2', '497.6760940676', '497.6760940676', '497.6760940676'],
['1.1', '3,4', '495.0455154634', '495.0455154634', '495.0455154634'],
['3.1', '3,4', '497.003633083', '497.003633083', '497.003633083']]
}
}
I am trying to get all the elements from data['Measurement1']['point1'][all_data_sets][2] to do a ','.join() for additional calculations later in the program. I'm hoping to get an output like:
'497.1937349917', '495.0455154634', '500.9453006597', '490.1952705428'
I'm currently looping through the array.
value_temp = []
for data_elem in data['Measurement1']['point1']:
value_temp.append(data_elem[2])
output = ','.join(value_temp)
Is there a way to grab these values without performing the loop?
output=','.join([data_elem[2] for data_elem in data['Measurement1']['point1']]). You can't beatO(n)for this though (think of it this way: to write each element to the string, you have to look at it. There's no way to "skip elements")