-8

If i have this as my code:

import sys
from sys import argv
if len(sys.argv) == 7:
    a,b,c,d,e,f,g = argv
    c_list = c.split(',')
    d_list = d.split(',')
    if len(c_list) == len(d_list):
        print b
    elif len(d_list) == len(c_list):
        print b
    else:
        sys.exit()
    for c in c_list:
        if len(c_list) == len(d_list):
            print c
        else:
            sys.exit()
    for d in d_list:
        if len(d_list) == len(c_list):
            print d
        else:
            sys.exit()
    print e
    print f
    print g

else:
    a,b,c,d,e,f = argv
    c_list = c.split(',')
    d_list = d.split(',')
    if len(c_list) == len(d_list):
        print b
    elif len(d_list) == len(c_list):
        print b
    else:
        sys.exit() 
    for c in c_list:
        if len(c_list) == len(d_list):
            print c
        else:
            sys.exit()
    for d in d_list:
        if len(d_list) == len(c_list):
            print d
        else:
            sys.exit()
    print e
    print f

It allows me to pass the following to argv:

a b c,c1,c2 d,d1,d2 e f g

and the other code I have leads to this list printing as

    a 
    b 
    c
    c1
    c2
    d
    d1
    d2
    e
    f
    g

However, I want it to print the following:

    a
    b
    c
    d
    e 
    f
    g
    a
    b
    c1
    d1
    e
    f
    g

and so on and so forth. How would I do this? If this seems super basic, I apologize. As a high school freshman, I am still trying to figure out how the complex world of coding works.

AkshatDas
  • 3
  • 3
  • I do not understand the logic behind your desired output. How do you get that? How exactly do you want it organized? You need to show us your code that does the printing; we can't possibly know what the error is otherwise. – TheSoundDefense Jul 21 '14 at 16:47
  • 1
    This is not valid Python syntax. What is this `a b c d e f g = argv`? Where is your user input coming from? – Cory Kramer Jul 21 '14 at 16:48
  • @TheSoundDefense I went ahead and added my whole code – AkshatDas Jul 21 '14 at 16:52
  • @user3861531 it's still not entirely clear what you're trying to achieve, but maybe something like [this](http://stackoverflow.com/a/23709681/3001761) or [this](http://stackoverflow.com/q/533905/3001761). – jonrsharpe Jul 21 '14 at 16:54
  • @jonrsharpe instead of it printing the different c values one after another, I wanted it to print the whole list again, with each print going through each additional c value. – AkshatDas Jul 21 '14 at 16:56
  • @user3861531 then `itertools.product` is probably what you want - check the links I just added. – jonrsharpe Jul 21 '14 at 16:56
  • If you want to iterate through `c` and `d` in pairs, you may want to `zip`, too. – jonrsharpe Jul 21 '14 at 17:03
  • @jonrsharpe and how would that work? – AkshatDas Jul 21 '14 at 17:16
  • @jonrsharpe I figured out how to zip the lists (c and d lists) but how do i write a print function that prints the rest of the list, with the zipped pairs mixed in? – AkshatDas Jul 21 '14 at 17:27

1 Answers1

0

From your description, I think you want something like this:

>>> a = 1
>>> b = 2
>>> c = [3, 4, 5]
>>> d = [6, 7, 8]
>>> for cx, dx in zip(c, d):
        for item in (a, b, cx, dx):
            print(item)
        print("---")


1
2
3
6
---
1
2
4
7
---
1
2
5
8
---
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437