Jan-06-2019, 01:36 PM
Hey, I do some coding challenges online and I have issue with this one.
At first I did this:
At first I did this:
>>> q = lambda s:['' if not s else c for c in s if s.count(c)<=1][0]
>>> q('~><#~><')
'#'But it throw some assertion error on website, something is bugged with their tests so I cant use any indexing and lists cause it throws out of range error, sounds like more challenge but Im stuck with:>>> def first_non_repeating_letter(x):
f=0
for i in list(x):
if i.isalpha():
f=x.count(i.lower())+x.count(i.upper())
else:
f+=x.count(i)
if f==1:
return i
return ""
>>> first_non_repeating_letter('~><#~><')
''It should return '#' but it returns "" or None so it basically jumps over the counting to the empty string case and I dont know why.
