Skip to content

Commit ea93c8f

Browse files
authored
Merge pull request #2 from Ismael-Duran/master
Solution in Python
2 parents a8209ff + a12d572 commit ea93c8f

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
# Note that this solution assumes a unique string
3+
# implies a lowercase letter and the uppercase of
4+
# that letter is not considered duplicates
5+
# example: the string "Hather" has an uppercase "H"
6+
# and lowercase "h" yet the string has no duplicate
7+
# "h" or "H"
8+
9+
10+
def uniqueChar(passedStr):
11+
12+
# Will use the built-in function set() which
13+
# eliminates dupplicates
14+
deleteDuplicateIfAny = set(passedStr)
15+
16+
# If the string had unique characters the string
17+
# length remains the same
18+
# If the string has duplicates then size
19+
if len(deleteDuplicateIfAny) == len(passedStr):
20+
return "Unique"
21+
else:
22+
return "Not Unique"
23+
24+
25+
example = "Helloh"
26+
27+
print(uniqueChar(example))
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
example = "hello"
2+
example2 = "ehloe"
3+
4+
for letter in example:
5+
if letter in example2:
6+
index = example2.index(letter)
7+
example2 = example2[:index] + example2[index+1:]
8+
print(example2)
9+
10+
if example2 == '':
11+
print("done with permutation")
12+
break
13+
else:
14+
continue
15+
else:
16+
print("Not permutatable")
17+
break
18+

Python/chapter01/1.3 - URLify/Q1.3.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
3+
def replaceSpace(stringPas, totalLen):
4+
# Use replace() to search for blank sapces in the string
5+
# and replace with "%20"
6+
newString = stringPas.replace(' ',"%20")
7+
8+
# Can use the length of string passed (second arg)
9+
# to check the length of new string is not greater
10+
# than original length
11+
if len(newString) > totalLen:
12+
return "Fail"
13+
else:
14+
return newString
15+
16+
print(replaceSpace("Hi, how is your ",18))

0 commit comments

Comments
 (0)