s = "hello world" print s.index("e") def palindrome(s): s = s[0:len(s)/2] for a in range(0, len(s)): if s[a] != s[-a-1]: print "not palindrome" return print "is palindrome" palindrome(s) def mysort(l): sorted_list = [] while len(l) > 0: a = 0 for b in l: if l[a] == min(l): sorted_list.append(l.pop(a)) a += 1 print sorted_list return sorted_list l = [4,7,2,5,8,5] mysort(l) def palindrome(s): s = s.lower() s = s.replace(' ', '') left = 0 for a in s: right = (left+1)*-1 if s[left] != s[right]: print "not palindrome" return left += 1 print "is palindrome" s = "Race car" palindrome(s) def median(l): l = mysort(l) print l if len(l) % 2 == 0: median = float(sum(l[len(l)/2-1:len(l)/2+1])) / 2 else: median = l[(len(l)-1) / 2] print median b = [4,6,5,7] median(b) def mode(l): mode = [1] for index, item in enumerate(l): if l.count(item) > mode[0]: mode[0] = item print l.count(mode[0]) l.pop(index) print l count = l.count(mode[0]) for index, item in enumerate(l): if l.count(index) == count: mode.append(item) print mode nl = [2,3,3,3,3,7,7,7,7,3] mode(nl)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question