I have a list of lists as follows
[('trojan', 'virus', 0.4731800100841465), ('elb', 'Ebola', 0.3722390506633956)]
How to extract only the middle element i.e. 'virus' and 'Ebola' ?
I have a list of lists as follows
[('trojan', 'virus', 0.4731800100841465), ('elb', 'Ebola', 0.3722390506633956)]
How to extract only the middle element i.e. 'virus' and 'Ebola' ?
You can use a comprehnesion list
your_list = [('trojan', 'virus', 0.4731800100841465), ('elb', 'Ebola', 0.3722390506633956)]
l = [x[1] for x in your_list]
output:
['virus', 'Ebola']
You have to find middle index
data = [
('trojan', 'virus', 0.4731800100841465),
('elb', 'Ebola', 0.3722390506633956)
]
middle_data = []
for inside_list in data:
middle = len(inside_list)/2
middle_data.append(inside_list[middle])
print(middle_data)
['virus', 'Ebola']