Link to home
Start Free TrialLog in
Avatar of jameskane
jameskane

asked on

Python - List Iteration output problem

The attached code produces an output of individual lists as shown below.
[1002, 2, 36, 4, 5]
[1003, 16, 17, 18, 14, 15]
[1081, 17, 19, 13, 22]
[1090, 4]
[1235, 34, 20, 30]
[120474, 25, 36, 29, 30]
[158846, 24, 27, 37, 30]
[169450, 1]
[272338, 10]
[274240, 5]
[416757, 11]
[436329, 29, 30]
[461640, 30, 3, 29, 14, 7]
[464860, 8, 1, 6, 7]
[491485, 33, 34, 3, 27, 22]
[524052, 10]
[529495, 29]
[590314, 23]
[659018, 24, 33, 27, 35, 30]
[890419, 9, 26, 25, 30, 7]
[980337, 19, 28, 22]
[997638, 1, 3, 6, 15]

My problem is that I need this output to be a single two dimensional list as shown below.  It seems really a straight forward thing to achieve, but I just can't manage it.  

Thanks for any help you can give me


[ [1002, 2, 36, 4, 5]
[1003, 16, 17, 18, 14, 15]
[1081, 17, 19, 13, 22]
[1090, 4]
[1235, 34, 20, 30]
[120474, 25, 36, 29, 30]
[158846, 24, 27, 37, 30]
[169450, 1]
[272338, 10]
[274240, 5]
[416757, 11]
[436329, 29, 30]
[461640, 30, 3, 29, 14, 7]
[464860, 8, 1, 6, 7]
[491485, 33, 34, 3, 27, 22]
[524052, 10]
[529495, 29]
[590314, 23]
[659018, 24, 33, 27, 35, 30]
[890419, 9, 26, 25, 30, 7]
[980337, 19, 28, 22]
[997638, 1, 3, 6, 15]]


#!C:\Python34\python.exe
import json
import traceback
import cgi,cgitb
import mysql.connector as conn
import collections
import datetime
import shelve
import copy
def htmlTop():
    print("""Content-type:text/html\n\n
        <!DOCTYPE html>
        <html lang="en">
            <head>

            <style>
            body {
        font-size: 100%; /*to support em text sizing*/
        margin-top: 0;

            }

            #backgrd_repeat_image {
        background-image: url(images/background.png);
        background-position: left top;
        background-repeat: repeat;
        height: 1cm;	/*padding-top: 15px;*/
            }


            </style>


                <meta charset="UTF-8">
                <title> Welcomme</title>

                <link href="registration.css" rel="stylesheet" type="text/css">


        </head>
        """)

def htmlTail():

    print("""    its done</body>
        </html>""")

def connectDB():
    db=conn.connect(host='localhost' ,user='root' ,passwd='844cheminduplan' ,db='python_office')
    cursor = db.cursor()
    return db, cursor 

def enrollments(db,cursor):
    sql = "select memberID,T1ytdlatest,T2ytdlatest,T3ytdlatest  from registrations;"
    cursor.execute(sql)
    results=cursor.fetchall()
    return results






#main program
if __name__== "__main__":
    try:
        htmlTop()
        db, cursor = connectDB()
        results = enrollments(db,cursor)
        for each in results:
            test = eval(each[1]) + eval(each[3]) + eval(each[2])
            test = list(set(test))
            member = each[0]
            test = [member] + test
            print(test)
            

        htmlTail()
    except:
        cgi.print_exception()

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Kyle Hamilton
Kyle Hamilton
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jameskane
jameskane

ASKER

Many thanks Kyle,  that worked !