# File: ChapterStrings/stringClear.py """ Python: L.find(x), L.count(x), L.replace('u', '') 0,1,1,0,0,0 011000 0,1,1,0,0,0 [1, 2] count how many 1's: 2 find first position of 1: 2 remove all commas: 011000 """ def myclear(S): #only 0 and 1 clear = '' for c in S: if (c == '1' or c == '0'): clear = clear + c return clear def mylist1(S): #list of indexes of 1 res = [] i = 0 #index for c in myclear(S): if ( c == '1'): res.append(i) i = i + 1 return res def main(): S = '0,1,1,0,0,0\n' # s string print(S,myclear(S)) # 011000 print(S,mylist1(S)) # positions of 1: [1,2] print("count how many 1's:",S.count('1')) # 2 print("find first position of 1:",S.find('1')) # 1 print("remove all commas:",S.replace(',','')) # 011000 main()