| | |
Find pediodicity in a list
A brute force method.
Finds the FIRST and SHORTEST periodicity in the input list.
Finds the FIRST and SHORTEST periodicity in the input list.
def find_period(inp): ''' Finds the FIRST and SHORTEST periodicity in the list: inp. Returns the position of the 0-based begin of the periodicity if any, and the length of it If it does not find any, returns None ''' pos=0 other=1 adjust=0 leninp=len(inp) while pos<leninp: try: other=inp.index(inp[pos],pos+1+adjust) except ValueError: other=None if other and other-pos<=leninp-other: for i in xrange(other,leninp): if inp[i-(other-pos)]!=inp[i]: adjust+=1 break else: return pos, other-pos else: adjust=0 pos+=1
Similar Threads
- How can I find and list the finalists? (Pascal and Delphi)
- How do you find the count of even numbers in a list? (Python)
- Find highest value in List (C++)
- how to find maximum value in linked list ?? please help. (C)
- Find and list folders (VB.NET)
| Thread Tools | Search this Thread |
abrupt alarm ansi anti approximation array assignment backend beginner binary bluetooth builtin calculator character cmd converter countpasswordentry curved customdialog cx-freeze dan08 data decimals dictionary directory exe file float format function generator getvalue gnu halp heads homework http ideas input ip itunes java leftmouse line linux list lists loop maintain maze millimeter module mouse mysqlquery number numbers output parsing path pointer prime programming push py2exe pygame python queue random recursion schedule screensaverloopinactive script scrolledtext slicenotation sqlite ssh statistics string strings sudokusolver terminal text thread time tlapse tuple twoup ubuntu unicode urllib urllib2 variable ventrilo vigenere web webservice wikipedia write wxpython xlib



