Home Page class 12 @ Python

CBSE Class 12 : Data Structures

Introduction to Data Structures

CBSE Class 12 : Searching

Creation And Traversal
What is Searching?
Linear/Sequential Search
Binary Search
Insertion Of Element
Deletion Of Element

CBSE Class 12 : Sorting

What is sorting?
Bubble Sort
Selection Sort
Insertion Sort

CBSE Class 12 : Stacks

Stacks
Applications of Stacks
Implementation of Stacks

CBSE Class 12 : Queues

Queues
Applications Of Queues
Implementation of Queues

Class 12 Data Structures | Stacks 8

Write a program to display vowels present in the given word using stacks.

Source Code

vowels=['a','e','i','o','u','A','E','I','O','U']
word=input("Enter the word ")
stack=[]
for letter in word:
    print(letter)
    if letter in vowels:
        stack.append(letter)

print("stack ",stack)
print("total different unique vowels are ",len(stack))

Output:

Enter the word computer
c
o
m
p
u
t
e
r
stack  ['o', 'u', 'e']
total different unique vowels are  3

Write a program to display unique vowels present in the given word using stacks.

Source Code

vowels=['a','e','i','o','u','A','E','I','O','U']
word=input("Enter the word ")
stack=[]
for letter in word:
    print(letter)
    if letter in vowels:
        
        if letter not in stack:
            stack.append(letter)

print("stack ",stack)
print("total different unique vowels are ",len(stack))

Output:

Enter the word hello
h
e
l
l
o
stack  ['e', 'o']
total different unique vowels are  2
Enter the word hellooooo
h
e
l
l
o
o
o
o
o
stack  ['e', 'o']
total different unique vowels are  2