| | |
Find pediodicity in a list
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
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 |
Tag cloud for Python
address anydbm app beginner cipher client code conversion coordinates curves development dictionary dynamic examples excel feet file float font format ftp function generator getvalue gui handling homework images import input ip java keycontrol line linux list lists loan loop maintain maze microcontroller millimeter mouse mysqldb newb number numbers output parsing path permissions port prime program programming projects py2exe pygame pymailer pyqt python queue random recursion recursive scrolledtext searchingfile shebang slicenotation socket split ssh string strings table terminal text thread threading time tkinter tlapse tooltip tuple tutorial type ubuntu unicode url urllib urllib2 variable variables vigenere web windows wx.wizard wxpython xlwt



