Reputation: 41
I am trying to get the value of the first index in the list and then use this value to print the value of the index which corresponds to this.
For example, in the list
[1,2,3,4,5,3]
I would like to print the value '2'
.
list_list = [5, 1.7, 1.6, 1.3, 1.4, 1.2, 1.3, 1.5, 1.6]
op_list = []
for k in list_list:
if(list_list[0] == list_list.index('k'):
op_list.append(k)
print(op_list)
Upvotes: 0
Views: 35
Reputation: 9833
Your question is a bit confusing, but if I'm not mistaken, you want to take the numerical value of list[0]
and then to print out the numerical value of the positional index for the value which was returned by list[0]
list_list = [1, 2, 3, 4, 5, 3]
print(list_list[list_list[0]])
>> 2
list_list = [5, 1.7, 1.6, 1.3, 1.4, 1.2, 1.3, 1.5, 1.6]
print(list_list[list_list[0]])
>> 1.2
Upvotes: 1