INTERVIEW QUESTION - Find out common letters between two strings Using Python
Vložit
- čas přidán 21. 01. 2020
- INTERVIEW QUESTION - Find out common letters between two strings Using Python
GitHub Link :- github.com/netsetos/python_co...
~-~~-~~~-~~-~
Please watch: "LRU Cache (With Python Code) "
• LRU Cache Implementati...
~-~~-~~~-~~-~
s1=input('enter a 1st string')
s2=input('enter a 2nd string')
s1 = set(list(s1))
s2 = set(list(s2))
common = list(s1.intersection(s2))
print(common)
Print(set(a for a in "S1" if a in "S2"))
Love the intro, keep it coming🔥🔥
If u keep carrier guidance that also help to all freshers mam 🙏
s1=input('enter a 1st string')
s2=input('enter a 2nd string')
common = set(s1).intersection(set(s2))
print(common)
res = ''
for st in s1:
if st in s2 and st not in res:
res+= st
print(res)
Nice mam
thank you
awesome lecture mam
Thanks a lot
What happens if input is maane and naane
{'A','N','E'}
Nice video
My Solution:
def c_letters(w1, w2):
set_w1=set(w1)
set_w2=set(w2)
print(set_w1 & set_w2)
please avoid the music ..
s1="naina"
s2="reene"
r=[]
for i in s1:
r.append(i)
for j in set(s2):
if j in r:
print(j)
s1=set(input("Enter string 1"))
It will just ignore the common elements...
str1="NAINA"
str2="REENE"
common=""
for i in str1:
if i in str2:
if i not in common:
common+=i
print(common)
s1=input('Enter name1:')
s2=input('Enter name2: ')
t=[]
for s in s1:
if s in s2:
if s in t:
continue
else:
t.append(s)
print(t)
This is also a good approach.
a = "abbcd"
b = "abbcdefg"
z = set()
for i in a:
for j in b:
if i == j:
z.add(i)
print(z)
s1=input('enter a 1st string')
s2=input('enter a 2nd string')
l=[ ]
for ch in s1:
if ch not in s2:
pass
else:
l.append(ch)
s3=' '.join(l)
print('{} is the common elements in the both string {} and {}'.format(s3,s1,s2))
Output please.?
@@arshiyashaik4982 output:NN
Or else u can go for following logic as well..
l1=list(input(' enter a 1st string'))
l2=list(input(' enter a 2nd string'))
s1=set(l1)
s2=set(l2)
print('The common element of above string is: ', ' '. Join(s1.intersection(s2)))
@@manjitjaiswar4990 ok
string1=input("Enter first string: Reene ")
string2=input("Enter second string: Naina ")
string1=set(string1)
string2=set(string2)
print(string1)
print(string2)
common_letters()
# Input two strings
string1 = input("Enter the first string: ")
string2 = input("Enter the second string: ")
# Convert the strings into sets of unique characters
set1 = set(string1)
set2 = set(string2)
# Find the common characters by taking the intersection of the sets
common_characters = set1.intersection(set2)
# Display the common characters
print("Common characters between the two strings:", common_characters)
def common():
a=input("Enter String 1: ")
b=input("Enter String 2: ")
ls=[]
for i in a:
for j in b:
if i == j and i not in ls:
ls.append(i)
print(f"Common Letter between the two strings are : {ls}")