SCHOOL OF CODE BUILDERS
Learn To CODE. Become A DEVELOPER.
Pages
HOME
DATA STRUCTURES
STRINGS
ARRAYS
MATRIX
BINARY TREES
LINKED LIST
STACK
QUEUE
SORTING
SEARCHING
C
PYTHON
PSEUDOCODE
CONTEST PROBLEMS
ALGORITHMS
PATTERNS
PHP
C PUZZLES
C INTERVIEW QUESTIONS
JAVA
C++
HASHING
RECURSION
BASIC C PROGRAMS
TCS-CODEVITA
FACEBOOK
CONTACT US
To get combinations of elements of a list
For example:
if the input is 1 2 3 , you have to print the output as the list of combinations of the number 1 2 3 which is [0, 1, 2, 3, 2, 3, 3, 3]
Python Implementation:
import itertools list=[] N,Q=map(int,raw_input().split()) s=raw_input() s=''.join(s.split()) ln=len(s) for j in range(ln): for i in itertools.combinations(s,j): list.append(''.join(i)) list.append(s) for i in range(1,len(list)): list[i]=int(max(list[i])) list[0]=0 while(Q>0): opnd,opr=map(str,raw_input().split()) Q-=1 print list
PREVIOUS
NEXT
HOME