Change language

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)" = ord ( ’a’ ) and ord (ch) " = 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 

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

News


Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method