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:
  • Twitter
  • Facebook
  • Instagram
  • Linkedin
  • Linkedin
Sunil Shaw

Sunil Shaw

  • Youtube
  • Instagram
  • Twitter
  • Facebook
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