We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent bf635f3 commit af1e20eCopy full SHA for af1e20e
Lab Cycle 2/program10.py
@@ -0,0 +1,16 @@
1
+# Program to Get a string from an input string where all occurrences of the first
2
+# character are replaced with ‘$’, except the first character. [eg: onion -> oni$n]
3
+
4
+# Function to replace the occurence of a character with $
5
+def replace_char(str):
6
+ unique_char = set() # To store unique characters
7
+ for i in range(0,len(str)): # loop to get the unique character
8
+ if str[i] in unique_char:
9
+ str=str[:i]+"$"+str[i+1:] # replace the character with $
10
+ else:
11
+ unique_char.add(str[i]) # add the unique character to the set
12
+ return str
13
14
+str = input("Enter a string: ")
15
+print(replace_char(str)) # Call the function
16
0 commit comments