1

I have written a sample code.

planets=[('aries','mars'),('tarus','venus'),('gemini','mercury'),  ('cancer','moon')]
print(planets)    
asc=[ ]    
for i in range(0,len(planets)):
   asc.append(planets[(i+1)%(len(planets))])        
print(asc) 

The first key is the sign and followed by its lord.

If aries is the ascendant, the sequence of houses and lords are as per the list. If tarus is the asc then the first will be tarus and the last will be aries and so

In my code I am able to print out only the second one. Why is my code not giving me the entire output?

Andy
  • 49,085
  • 60
  • 166
  • 233
  • 2
    It does not come fully clear what you want to achieve. It it simply shifting the list? Please show expected output and actual output. – flaschbier Feb 23 '16 at 04:32

3 Answers3

1

It appears from the number that you want to rotate the list contents. that is, each time you want to say

def rotate(planets):
    temp = planets[0]
    n = len(planets)
    for i in range(1, n):
        planets[i-1] = planets[i]
    planets[-1] = temp
    return planets

This does it once. In order to do it each time, call rotate the correct number of times

planets=[('aries','mars'),('tarus','venus'),('gemini','mercury'), ('cancer','moon')]
for j in range(len(planets)):
    print planets
    planets = rotate(planets)

By the end, planets has returned to the first value and has printed all four values.

[('aries', 'mars'), ('taurus', 'venus'), ('gemini', 'mercury'), ('cancer', 'moon')]
[('taurus', 'venus'), ('gemini', 'mercury'), ('cancer', 'moon'), ('aries', 'mars')]
[('gemini', 'mercury'), ('cancer', 'moon'), ('aries', 'mars'), ('taurus', 'venus')]
[('cancer', 'moon'), ('aries', 'mars'), ('taurus', 'venus'), ('gemini', 'mercury')]
sabbahillel
  • 4,357
  • 1
  • 19
  • 36
1

Assuming you don't want to simply rotate but follow the pattern in your title, then it would be easier to maintain 2 lists (and for efficiency use collectiones.deque), pop from the left of one list and push to the left of the other, e.g.:

import itertools as it
from collections import deque
a1 = deque(planets)
a2 = deque()

for i in range(len(planets)):
    print(list(it.chain(a1,a2)))
    a2.appendleft(a1.popleft())

Output ([1,2,3,4], [2,3,4,1], [3,4,2,1] and [4,3,2,1]):

[('aries', 'mars'), ('tarus', 'venus'), ('gemini', 'mercury'), ('cancer', 'moon')]
[('tarus', 'venus'), ('gemini', 'mercury'), ('cancer', 'moon'), ('aries', 'mars')]
[('gemini', 'mercury'), ('cancer', 'moon'), ('tarus', 'venus'), ('aries', 'mars')]
[('cancer', 'moon'), ('gemini', 'mercury'), ('tarus', 'venus'), ('aries', 'mars')]
AChampion
  • 29,683
  • 4
  • 59
  • 75
0

Using your method:

planets=[('aries','mars'),('tarus','venus'),('gemini','mercury'),  ('cancer','moon')]
print(planets)
temp = planets
for j in range(len(planets)-1):
    asc = []
    for i in range(len(planets)):
        asc.append(temp[(i+1)%(len(planets))])
    temp = asc
    print(asc)

You just had to save the newly made lists in a temporary variable and put that inside another loop to get all 4 possibilities.

ml-moron
  • 888
  • 1
  • 11
  • 22