Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

Remove duplicates in a given elements?

Q) Write a program to remove duplicates in a given elements?

Sample Input:-

Enter elements separated by space :
2 3 4 2 2 2 2 2 2 2 1 1 2 3 1 2

Output:-

1 2 3 4

Python code:-


l=[]
print "Enter elements separated by space : "
l=map(int,raw_input().split())
l=list(set(l))
for i in range(len(l)):
      print l[i],



Count frequency of characters in string

Q) Write a program to count frequency of characters in given string?

Sample Input:--

Enter a string :  python programming

Output:-

a 1
g 2
h 1
i 1
m 2
n 2
o 2
p 2
r 2
t 1
y 1

python code:-


s=raw_input("Enter a stirng : ")
al='abcdefghijklmnopqrstuvwxyz'
au='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
l=[0]*26
m=[0]*26
for i in range(26):
    l[i]=s.count(al[i])
    m[i]=s.count(au[i])
for i in range(26):
    if l[i]!=0:
        print al[i],l[i]
    if m[i]!=0:
        print au[i],m[i]

Reverse a String simple program in python

Q) Write a simple python program to reverse a given String?

Python Code:-

s=raw_input("Enter a stirng : ")
print s[::-1]


Output:-

Technicaldeal.com Python reverse string