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
Post a Comment