-1

Note: I'm working in python on this.

For example given a list:

list = ['E','D','F']

I want to generate all rules of the following forms:

['E']     --> ['D','F']
['D']     --> ['E','F']
['F']     --> ['E','D']
['E','D'] --> ['F']
['E','F'] --> ['D']
['D','F'] --> ['E']
Vijesh
  • 795
  • 3
  • 9
  • 23
  • 1
    Possible duplicate of [How to get all possible combinations of a list’s elements?](http://stackoverflow.com/questions/464864/how-to-get-all-possible-combinations-of-a-list-s-elements) – gnikit Apr 10 '17 at 07:17

1 Answers1

0

Look at the answer of Dan H here and at the Python documentation

Code should look something like:

import itertools

letters = ['E','D','F']
for i in range(len(letters)+1):
    for j in itertools.combinations(letters, i):
        print j

This provides the following output:

()
('E',)
('D',)
('F',)
('E', 'D')
('E', 'F')
('D', 'F')
('E', 'D', 'F')

If you don't want the output () just use for i in range(1,len(letters)+1):

Community
  • 1
  • 1
gnikit
  • 1,031
  • 15
  • 25
  • I don't want combinations but i want output in the form of rules as i mentioned above in my questions... – Vijesh Apr 11 '17 at 08:17
  • @Vijesh - What do you mean by "form of rules" ? Care to elaborate or provide a link to documentation – gnikit Apr 11 '17 at 08:23