ezoic

Thursday, March 9, 2017

Python problem 7

Write a Python program to create and display all combinations of letters, selecting each letter from a different key in a dictionary.

class Solution:
    def comb1(self,dict1):

        list1=[]
        for key in dict1.keys():
            for key2 in dict1.keys():
                if key!=key2:
                    for i in range(len(dict1[key])):
                        for j in range(len(dict1[key2])):
                            a1=dict1[key][i]+dict1[key2][j]
                            list1.append(a1)
        list2=[]
        for item in list1:
            item=sorted(item)
            item="".join(item)
            list2.append(item)
        list2=list(set(list2))


        return(list2)

kk=Solution()

if __name__=="__main__":

    print(kk.comb1({'1':['a','b'],'2':['c','d']}))


No comments:

Post a Comment

looking for a man

 I am a mid aged woman. I live in southern california.  I was born in 1980. I do not have any kid. no compliacted dating.  I am looking for ...