Write a Python program to print a specified list after removing the 0th, 4th and 5th elements

  • Last updated: September 4, 2024 By Sunil Shaw

Sample List : [‘Red’, ‘Green’, ‘White’, ‘Black’, ‘Pink’, ‘Yellow’]
Expected Output : [‘Green’, ‘White’, ‘Black’]

def func(lst):
    new_list = []
    rm_list = [0, 4, 5]
    for i in range(len(lst)):
        if i not in rm_list:
            new_list.append(lst[i])
    return new_list
     
l = ['Red', 'Green', 'White', 'Black', 'Pink', 'Yellow']
print(func(l))


Follow on:
Sunil Shaw

Sunil Shaw

About Author

I am a Web Developer, Love to write code and explain in brief. I Worked on several projects and completed in no time.

Popular Language Tutorials

If You want to build your own site Contact Us