So my goal for this problem is to, given 2 strings, str1
and str2
, create a dictionary such that the characters in str1
are the keys and the corresponding characters in str2
are the values.
ie. crackthecode('apple','byytr')
returns
{'a':'b','p':'y','l':'t','e':'r'}
and if it is inconsistent, ie. crackthecode('apple','byptr')
then returns
{}
, an empty dictionary.
This is my code, I'm just not sure how to do the inconsistent case.
PS. I cannot use zip
for this question.
Below is my code.
def crackthecode(str1, str2):
final = {}
x = 0
for i in list(str1):
final[i]=str2[x]
x = x + 1
return final
All help is appreciated, thanks!