Set of pythons | Pairs of complete strings in two sets



Examples:

 Input: set1 [] = {"abcdefgh", "pythonengineering", "lmnopqrst", "abc"} set2 [] = {"ijklmnopqrstuvwxyz", "abcdefghijklmnopqrstuvwxyrst." "} Output: 7 The total complete pairs that are forming are :" abcdefghijklmnopqrstuvwxyz "" abcdefghabcdefghijklmnopqrstuvwxyz "" abcdefghdefghijklmnopqrstuvwxyz "" pythonengineeringabcdefghijklmnopqrstuvwxyz "" lmnopqrstabcdefghijklmnopqrstuvwxyz "" abcabcdefghijklmnopqrstuvwxyz "" abcdefghijklmnopqrstuvwxyz "  

 we have the solution this problem, please refer to the Set data structure . The approach is very simple,

  1. Consider all pairs of strings, concatenate them one by one and convert them to a set.
  2. Now add all the alphabets in the concatenated string to the set one by one. Since the set contains unique values, so if the set length is 26, it means that the set contains all 26 English alphabets.

# Function for search for pairs of complete lines
# in two sets of lines

 

def completePair (set1, set2):

  

  # view all line pairs from

# set1 and set2

count = 0

for str1 in set1:

  for str2 in set2:

  result = str1 + str2

 

# push all letters of the alphabet

# string to temporary set

tmpSet = set ([ch for ch in result if ( ord (ch) & gt; = ord ( `a` ) and ord (ch) & lt; = ord ( `z` ))])

if len (tmpSet) = = 26 :

count = count +   1

print (count)

 
# Driver program

if __ name__ = = "__ main__" :

set1 = [ `abcdefgh` , ` pythonengineering` , `lmnopqrst` , ` abc` ]

  set2 = [ `ijklmnopqrstuvwxyz` , ` abcdefghijklmnopqrstuvwxyz` , `defghijklmnopqrstuvwxyz` ]

  completePair (set1, set2)

Exit:

 7