Advertisement
Programmin-in-Python

Finding the Number of Common Letters in an Array of Strings

Dec 29th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.55 KB | None | 0 0
  1. def common(arr):
  2.     L1 = []
  3.  
  4.     for i in range(len(arr)-1):
  5.         str1 = arr[i]
  6.  
  7.         for j in str1:
  8.             str2 = arr[i+1]
  9.  
  10.             if str2.find(j) >= 0:
  11.                 if j not in L1:
  12.                     L1.append(j)
  13.  
  14.     i = 0
  15.     found = True
  16.  
  17.     while i < len(L1):
  18.         j = 0
  19.  
  20.         while j < len(arr):
  21.             if (arr[j].find(L1[i])) < 0:
  22.                 found = False
  23.                 break
  24.  
  25.             elif (arr[j].find(L1[i])) >= 0:
  26.                 found = True
  27.  
  28.             j += 1
  29.  
  30.         if not found:
  31.             L1.pop(i)
  32.             i = 0
  33.         else:
  34.             i += 1
  35.  
  36.         found = True
  37.         continue
  38.  
  39.     return len(L1)
  40.  
  41. val = common(['abc', 'bac', 'ab'])
  42. print(val)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement