-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
43 lines (40 loc) · 1.07 KB
/
utils.py
File metadata and controls
43 lines (40 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# -*- coding: utf-8 -*-
# some functions (principally used by orthocheck)
## test if a word contains digits or uppercase letters
def digit_in(word):
return any(char.isdigit() for char in word)
def upper_in(word):
return any(char.isupper() for char in word)
## some functions to format word in the 'wiki way'
def wiki_text_bf(word):
return "'''" + word + "'''"
def wiki_text_it(word):
return "''" + word + "''"
def wiki_text_sec(word):
return "== " + word + " =="
def wiki_text_ssec(word):
return "=== " + word + " ==="
## simple binary search algorithm
def binary_search(val, tab):
found = False
i_i = 0
i_f = len(tab)-1
if tab[i_i] == val:
return i_i
elif tab[i_f] == val:
return i_f
while (not found) and ((i_f - i_i) > 1):
i_m = (i_i + i_f) / 2
# print i_m
found = (tab[i_m] == val)
# print found
if tab[i_m] > val:
i_f = i_m
else:
i_i = i_m
if tab[i_i] == val:
return i_i
elif tab[i_f] == val:
return i_f
else:
return -1