0

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' ?

venkatttaknev
  • 669
  • 1
  • 7
  • 21
  • `print([i[1] for i in [('trojan', 'virus', 0.4731800100841465), ('elb', 'Ebola', 0.3722390506633956)] ])` ? – Rakesh Feb 04 '19 at 10:17

2 Answers2

1

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']
BlueSheepToken
  • 5,751
  • 3
  • 17
  • 42
0

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)

Output: ['virus', 'Ebola']

anjaneyulubatta505
  • 10,713
  • 1
  • 52
  • 62