Saturday, July 20, 2024

Python Technical Interview Questions

 1)first non repeating character

Malayalam

y

programming

p



str = "MalayalaM"


a = '\0'

for c in str:

    if str.index(c) == str.rindex(c):

        a = c

        break


print(a)




2)



1

##

333

####

55555




for i in range(1, 6):

    for j in range(1, i+1):

        if i % 2 != 0:

            print(i, end='')

        else:

            print('#', end='')

    print()



3)


find two elements of array for given target sum


  a = {2, 11, 7, 15};

  target = 9;


output is


2,7



a = [2, 11, 7, 15]

target = 9

for i in range(len(a)):

 for j in range(i + 1, len(a)):

   if a[i] + a[j] == target:

    print(a[i],a[j])




4)union of two list



a=[1,2,3,4,5]

b=[3,2,6,7,8]



output

[1, 2, 3, 4, 5, 6, 7, 8]




a=[1,2,3,4,5]

b=[3,2,6,7,8]


set1=set(a)

set2=set(b)


set3=set1.union(set2)

print(set3)




5)intersection of two list


a=[1,2,3,4,5]

b=[3,2,6,7,8]



output


[2,3]



a=[1,2,3,4,5]

b=[3,2,6,7,8]


for i in range(len(a)):

    for j in range(i+1):

        if a[i] == b[j]:

            print(a[i])



6)Check if a String is a Palindrome


mam

reverse mam


a = "mam"

b = a[::-1]


if a == b:

    print("polindrome")

else:

    print("not polindrome")



7)remove duplicate in  name


input sabari


output sabri



a="sabari"

s=''.join(dict.fromkeys(a))

print(s)







No comments:

Post a Comment

Python Technical Interview Questions

 1)first non repeating character Malayalam y programming p str = "MalayalaM" a = '\0' for c in str:     if str.index(c) ==...