Answer to Question #285622 in Python for nishitha

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.


1
Expert's answer
2022-01-08T01:34:53-0500

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))


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS