diff options
Diffstat (limited to 'challenge-092/paulo-custodio/python/ch-1.py')
| -rw-r--r-- | challenge-092/paulo-custodio/python/ch-1.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/challenge-092/paulo-custodio/python/ch-1.py b/challenge-092/paulo-custodio/python/ch-1.py new file mode 100644 index 0000000000..70e334812e --- /dev/null +++ b/challenge-092/paulo-custodio/python/ch-1.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python + +# Challenge 092 +# +# TASK #1 > Isomorphic Strings +# Submitted by: Mohammad S Anwar +# You are given two strings $A and $B. +# +# Write a script to check if the given strings are Isomorphic. Print 1 if they +# are otherwise 0. +# +# Example 1: +# Input: $A = "abc"; $B = "xyz" +# Output: 1 +# Example 2: +# Input: $A = "abb"; $B = "xyy" +# Output: 1 +# Example 3: +# Input: $A = "sum"; $B = "add" +# Output: 0 + +import sys + +def isomorphic(a,b): + if len(a)!=len(b): + return 0 + else: + mapping = {} + mapped = {} + for i in range(0, len(a)): + if not a[i] in mapping: # a is new + if b[i] in mapped: # b already mapped to some other a + return 0 + else: # store mapping + mapping[a[i]] = b[i] + mapped[b[i]] = 1 + else: # a already occurred + if mapping[a[i]]!=b[i]: # previous mapping is different + return 0 + return 1 + +print(isomorphic(sys.argv[1], sys.argv[2])) |
