Advertisement
here2share

# groupby.py

Jul 19th, 2023
886
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.48 KB | None | 0 0
  1. # groupby.py
  2.  
  3. from itertools import groupby
  4.  
  5. def look_and_say(iterations, sequence='1'):
  6.     arr = [sequence]
  7.     def get_sequence(arr,iterations,sequence):
  8.         if iterations == 0:
  9.             return arr
  10.         else:
  11.             current = ''.join(str(len(list(group))) + key for key,group in groupby(sequence))
  12.             arr.append(current)
  13.             get_sequence(arr,iterations-1,current)
  14.         return arr
  15.  
  16.     final_sequence = get_sequence(arr,iterations,sequence)
  17.     return '\n'.join(final_sequence)
  18.    
  19. print (look_and_say(15))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement