0

This is what I am trying to achieve while using Sage worksheet interface.

Assume that I wrote a code and it gave, for example, for each i in a range of lists, list[0]. (First element of each list) So I have multiple outputs. Now I want to use these outputs, consider them as a list, and take iterative combinations of elements of it. Can I do that, and how?

kcrisman
  • 4,374
  • 20
  • 41
S.B.
  • 165
  • 1
  • 8

2 Answers2

1

Probably it is easiest to make a new list out of this.

for list in list_of_lists:
    list[0]

could become (I'm making a minimal change to your code)

new_list = []
for ls in list_of_lists:
    new_list.append(ls[0])

and then new_list should have what you want. (For more concise ways to do this, learn about Python list comprehensions.)

kcrisman
  • 4,374
  • 20
  • 41
  • I am using Sage cloud interface. – S.B. Oct 22 '14 at 05:50
  • You shouldn't use `list` as a variable name, as it shadows the built-in `list`. – chthonicdaemon Oct 22 '14 at 06:52
  • True, that was a bit lazy (though in practice I have been able to avoid problems with it). I'll edit that. Edit: Actually, it was to avoid making big changes in the original code from the OP, but oh well. – kcrisman Oct 22 '14 at 12:45
1

I did this for L a list of lists and lf = len(L) and it worked.

liste = [list(L[i])[0] for i in range (1,lf)]
for (f1,f2,f3) in Combinations(liste,3):
..
S.B.
  • 165
  • 1
  • 8