Question #285622

write a method called solve which takes as parameter a list of tuples called A.

Each tuple contains some strings. You have to print the indexes of those tuples whose first element's first alphabet is the same as the last element's last alphabet.

Example, for this list:

[('hello','hi'), ('his', 'name', 'archith'), ('kremlin', 'russia', 'spartak'), ('error', 'none', 'wave'), ('indeed', 'numbers', 'work')]

The output is:

1 2 3

Because tuples in index 1 2 and 3 obey the given condition.


Expert's answer

test_list = [('a', 2), ('c', 3), ('d', 4)]

sort_order = [4, 2, 3]

print ("The original list is : " + str(test_list))

print ("The sort order list is : " + str(sort_order)

res = list(sorted(test_list,

   key = lambda i: sort_order.index(i[1])))

print ("The list after appropriate sorting : " + str(res))


LATEST TUTORIALS
APPROVED BY CLIENTS