d
WE ARE EXPERTS IN TECHNOLOGY

Let’s Work Together

n

StatusNeo

Python Program to return vowels in a string using Decorators

Scenario-

You are asked to write a program to demonstrate the usage of decorators in which the user will provide input and you are required to create a function that will be decorated in a way such that only vowels in the input are returned.

Solutions-

First Solution-

  • We will create a decorator named a decorator.
  • Then we will create an inner function inside it let’s name it a wrapper.
  • Now, let’s initialize a string consisting of vowels both in the upper and lower case.
  • After that, we will be calling the function that is decorated and is returning the string.
  • We will be using list comprehension to create a new list that will contain only vowels in the string returned by our main function.
  • In the end, we will join the list using join and will return that.

Second Solution-

  • We will create a decorator named a decorator.
  • Then we will create an inner function inside it let’s name it a wrapper.
  • Now, let’s initialize a string consisting of consonants both in the upper and lower case.
  • After that, we will be calling the function that is decorated and is returning the string.
  • In the end, We will use list comprehension inside join and will return the output string comparing with the consonants.

Third Solution-

  • This is the brute force solution
  • All the steps remain the same till calling the main function
  • We will iterate through the input and will check if the word belongs to vowels or not, if not then we will replace the word with space.

Still Curious? Visit my website to know more!

For more interesting Blogs Visit- Utkarsh Shukla Author

I am a versatile professional who specializes in empowering businesses with digital solutions. With expertise in software engineering consulting, I provide valuable guidance and support to companies seeking to enhance their technological capabilities. Additionally, I excel as a host(Professionals Unplugged), author, poet, and photographer. This diverse skill set allows me to creatively express my thoughts and ideas through various mediums. As a host, I engage audiences and facilitate insightful conversations. As an author, my writings offer valuable insights and knowledge. As a poet, I capture emotions and experiences through the power of words. And as a photographer, I have a keen eye for capturing captivating visuals. Overall, my wide range of skills and experiences make me a valuable asset in the world of digital solutions and creative expression

Comments

Add Comment