python3 return a list of indexes of a specific character in a string
string='mississippi'
s='s'
lst= []
for i in range(len(string)):
if (string[i] == s):
lst.append(i)
print(lst)
#result: [2, 3, 5, 6]
python3 return a list of indexes of a specific character in a string
string='mississippi'
s='s'
lst= []
for i in range(len(string)):
if (string[i] == s):
lst.append(i)
print(lst)
#result: [2, 3, 5, 6]
replace all character in string javascript
let a = "How to search and replace a char in a string";
while (a.search(" ", ""))
{
a = a.replace(" ", "");
}
console.log(a);
first unique character in a string python
class Solution(object):
def firstUniqChar(self, s):
"""
:type s: str
:rtype: int
"""
frequency = {}
for i in s:
if i not in frequency:
frequency[i] = 1
else:
frequency[i] +=1
for i in range(len(s)):
if frequency[s[i]] == 1:
return i
return -1
ob1 = Solution()
print(ob1.firstUniqChar("people"))
print(ob1.firstUniqChar("abaabba"))
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us