Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- s = raw_input('give a string: ')
- n = len(s)
- low = 0
- high = n-1
- ans = (high-low)/2
- x = ()
- l = ''
- print "Give a letter: "
- l = sys.stdin.read(1)
- if n != 0:
- if l != s[0] and l != s[n-1]:
- if l == s[ans]:
- a = 0
- b = 1
- while l == s[ans-a]:
- x = x + (ans-a,)
- a += 1
- while l == s[ans+b]:
- x = x + (ans+b,)
- b += 1
- else:
- while l != s[ans]:
- if s[ans] > l:
- high = ans
- else:
- low = ans
- ans = (high + low)/2
- if low == ans or high == ans:
- break
- a = 0
- b = 1
- while l == s[ans-a]:
- x = x + (ans-a,)
- a += 1
- while l == s[ans+b]:
- x = x + (ans+b,)
- b += 1
- if l == s[0]:
- a = 0
- while l == s[a]:
- x = x + (a,)
- a += 1
- if a >= n:
- break
- if l == s[n-1] and l != s[0]:
- b = 1
- while l == s[n-b]:
- x = x + (n-b,)
- b += 1
- if x == ():
- print 'Er zit geen %s in de gegenven string!' % l
- else:
- print "%s" % (x,)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement