python - How to print this pattern using Tuples? -


i new python tuples, , doing learning exercise on same. how should print following pattern when input string hi,hello,welcome.

(('hi', 'hello', 'welcome'),)  ((('hi', 'hello', 'welcome'),),)  (((('hi', 'hello', 'welcome'),),),)  

my attempt

n = input() arr = tuple(raw_input().split()) arr1 = list() print arr while(n>0) :     print(tuple(arr,))     n -= 1 

just define (or create) tuple @ start, nest on (reusing same variable):

n = 3 arr = ('hi','hello','welcome')  # or tuple(raw_input().split())  while(n>0):     arr = (arr,)  # that's enough create tuple inside tuple     print(arr)     n -= 1 

result:

(('hi', 'hello', 'welcome'),) ((('hi', 'hello', 'welcome'),),) (((('hi', 'hello', 'welcome'),),),) 

Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -