Write Python3 code to demonstrate Kth Non-None String from Rear using next() + list comprehension


Topic: Write Python3 code to demonstrate Kth Non-None String from Rear using next() + list comprehension

Solution

test_list = ["", "", "Akshat", "Nikhil"] 
print("The original list : " + str(test_list)) 
K = 2
test_list.reverse() 
test_list = iter(test_list) 
for idx in range(0, K): 
    res = next(sub for sub in test_list if sub) 
print("The Kth non empty string from rear is : " + str(res)) 



List all Python Programs