Print list items containing all characters of a given word | Python program to print the list items containing all characters of a given word ; Prints list items having all characters of word ; Set the values in map ; Get the length of given word ; Check each item of list if has all characters of words ; unset the bit so that strings like sss not printed ; Set the values in map for next item ; Driver program to test the above function
NO_OF_CHARS = 256 NEW_LINE def printList ( list , word , list_size ) : NEW_LINE INDENT map = [ 0 ] * NO_OF_CHARS NEW_LINE for i in word : NEW_LINE INDENT map [ ord ( i ) ] = 1 NEW_LINE DEDENT word_size = len ( word ) NEW_LINE for i in list : NEW_LINE INDENT count = 0 NEW_LINE for j in i : NEW_LINE INDENT if map [ ord ( j ) ] : NEW_LINE INDENT count += 1 NEW_LINE map [ ord ( j ) ] = 0 NEW_LINE DEDENT DEDENT if count == word_size : NEW_LINE INDENT print i NEW_LINE DEDENT for j in xrange ( len ( word ) ) : NEW_LINE INDENT map [ ord ( word [ j ] ) ] = 1 NEW_LINE DEDENT DEDENT DEDENT string = " sun " NEW_LINE list = [ " geeksforgeeks " , " unsorted " , " sunday " , " just " , " sss " ] NEW_LINE printList ( list , string , 5 ) NEW_LINE