Python: […] at End of List












-1















I've run into an issue when after I append my list to my dictionary, I get an unwanted [...] at the end of my list.



Here's my code:



class Account:

accountInfo = {} #ex. ID : 5FE19C (hexadecimal ID's)

def __init__(self):
choice = raw_input("Would you like to login or signup?n")
if choice.lower() == "login":
self.login()

elif choice.lower() == "signup":
print "Great! Fill in the following."
self.signup()

else:
self.__init__()

def signup(self):

accountID = '%010x' % random.randrange(16**10) # 10 digit hexadecimal ID generator
personalInfo =

self.accountInfo[accountID] = personalInfo

firstName = raw_input("First Name: ")
lastName = raw_input("Last Name: ")
email = raw_input("E-Mail: ")
password = raw_input("Password: ")
birthdate = raw_input("DOB (DD/MM/YYYY): ")
alias = raw_input("Username/Alias: ")

personalInfo.append(firstName)
personalInfo.append(lastName)
personalInfo.append(email)
personalInfo.append(password)
personalInfo.append(birthdate)
personalInfo.append(alias)

self.accountInfo[accountID].append(personalInfo)

print self.accountInfo


And here is my output:



>>> {'a92ab2fcea': ['firstName', 'lastName', 'email', 'password', 'birthdate', 'alias', [...]]}


Just wondering why it appears and how to remove it.



Thanks!










share|improve this question


















  • 1





    The Ellipses indicates a recursively defined structure. In your cases you have appended the list to itself.

    – Klaus D.
    Nov 23 '18 at 3:07
















-1















I've run into an issue when after I append my list to my dictionary, I get an unwanted [...] at the end of my list.



Here's my code:



class Account:

accountInfo = {} #ex. ID : 5FE19C (hexadecimal ID's)

def __init__(self):
choice = raw_input("Would you like to login or signup?n")
if choice.lower() == "login":
self.login()

elif choice.lower() == "signup":
print "Great! Fill in the following."
self.signup()

else:
self.__init__()

def signup(self):

accountID = '%010x' % random.randrange(16**10) # 10 digit hexadecimal ID generator
personalInfo =

self.accountInfo[accountID] = personalInfo

firstName = raw_input("First Name: ")
lastName = raw_input("Last Name: ")
email = raw_input("E-Mail: ")
password = raw_input("Password: ")
birthdate = raw_input("DOB (DD/MM/YYYY): ")
alias = raw_input("Username/Alias: ")

personalInfo.append(firstName)
personalInfo.append(lastName)
personalInfo.append(email)
personalInfo.append(password)
personalInfo.append(birthdate)
personalInfo.append(alias)

self.accountInfo[accountID].append(personalInfo)

print self.accountInfo


And here is my output:



>>> {'a92ab2fcea': ['firstName', 'lastName', 'email', 'password', 'birthdate', 'alias', [...]]}


Just wondering why it appears and how to remove it.



Thanks!










share|improve this question


















  • 1





    The Ellipses indicates a recursively defined structure. In your cases you have appended the list to itself.

    – Klaus D.
    Nov 23 '18 at 3:07














-1












-1








-1








I've run into an issue when after I append my list to my dictionary, I get an unwanted [...] at the end of my list.



Here's my code:



class Account:

accountInfo = {} #ex. ID : 5FE19C (hexadecimal ID's)

def __init__(self):
choice = raw_input("Would you like to login or signup?n")
if choice.lower() == "login":
self.login()

elif choice.lower() == "signup":
print "Great! Fill in the following."
self.signup()

else:
self.__init__()

def signup(self):

accountID = '%010x' % random.randrange(16**10) # 10 digit hexadecimal ID generator
personalInfo =

self.accountInfo[accountID] = personalInfo

firstName = raw_input("First Name: ")
lastName = raw_input("Last Name: ")
email = raw_input("E-Mail: ")
password = raw_input("Password: ")
birthdate = raw_input("DOB (DD/MM/YYYY): ")
alias = raw_input("Username/Alias: ")

personalInfo.append(firstName)
personalInfo.append(lastName)
personalInfo.append(email)
personalInfo.append(password)
personalInfo.append(birthdate)
personalInfo.append(alias)

self.accountInfo[accountID].append(personalInfo)

print self.accountInfo


And here is my output:



>>> {'a92ab2fcea': ['firstName', 'lastName', 'email', 'password', 'birthdate', 'alias', [...]]}


Just wondering why it appears and how to remove it.



Thanks!










share|improve this question














I've run into an issue when after I append my list to my dictionary, I get an unwanted [...] at the end of my list.



Here's my code:



class Account:

accountInfo = {} #ex. ID : 5FE19C (hexadecimal ID's)

def __init__(self):
choice = raw_input("Would you like to login or signup?n")
if choice.lower() == "login":
self.login()

elif choice.lower() == "signup":
print "Great! Fill in the following."
self.signup()

else:
self.__init__()

def signup(self):

accountID = '%010x' % random.randrange(16**10) # 10 digit hexadecimal ID generator
personalInfo =

self.accountInfo[accountID] = personalInfo

firstName = raw_input("First Name: ")
lastName = raw_input("Last Name: ")
email = raw_input("E-Mail: ")
password = raw_input("Password: ")
birthdate = raw_input("DOB (DD/MM/YYYY): ")
alias = raw_input("Username/Alias: ")

personalInfo.append(firstName)
personalInfo.append(lastName)
personalInfo.append(email)
personalInfo.append(password)
personalInfo.append(birthdate)
personalInfo.append(alias)

self.accountInfo[accountID].append(personalInfo)

print self.accountInfo


And here is my output:



>>> {'a92ab2fcea': ['firstName', 'lastName', 'email', 'password', 'birthdate', 'alias', [...]]}


Just wondering why it appears and how to remove it.



Thanks!







python list dictionary






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 23 '18 at 2:57









H4MMYH4MMY

36




36








  • 1





    The Ellipses indicates a recursively defined structure. In your cases you have appended the list to itself.

    – Klaus D.
    Nov 23 '18 at 3:07














  • 1





    The Ellipses indicates a recursively defined structure. In your cases you have appended the list to itself.

    – Klaus D.
    Nov 23 '18 at 3:07








1




1





The Ellipses indicates a recursively defined structure. In your cases you have appended the list to itself.

– Klaus D.
Nov 23 '18 at 3:07





The Ellipses indicates a recursively defined structure. In your cases you have appended the list to itself.

– Klaus D.
Nov 23 '18 at 3:07












2 Answers
2






active

oldest

votes


















0














To understand what exactly happened, you need to know about references.



>>> a = 
>>> test['a'] = a
>>> a.append(1)
>>> a.append(2)
>>> test['a']
[1, 2]


When you did the line self.accountInfo[accountID] = personalInfo
What it actually did was pass the reference of personalInfo to self.accountInfo[accountID]



Meaning modifying personalInfo will also reflect in self.accountInfo[accountID]



self.accountInfo[accountID] = personalInfo >> {'a92ab2fcea': }

personalInfo.append(firstName) >> {'a92ab2fcea': ['firstName']} # Note: Since personalInfo changed, so self.accountInfo[accountID] also changed.

personalInfo.append(lastName) >> {'a92ab2fcea': ['firstName','lastName']}

personalInfo.append(email) >> {'a92ab2fcea': ['firstName','lastName','email']}

personalInfo.append(password) >> {'a92ab2fcea': ['firstName','lastName','email','password']}

personalInfo.append(birthdate) >> {'a92ab2fcea': ['firstName','lastName','email','password','birthdate']}

personalInfo.append(alias) >> {'a92ab2fcea': ['firstName','lastName','email','password','birthdate','alias']}

self.accountInfo[accountID].append(personalInfo) >> {'a92ab2fcea': ['firstName', 'lastName', 'email', 'password', 'birthdate', 'alias', [...]]} # What you are doing is appending personalInfo to personalInfo


What I think you meant to do is:




  1. remove self.accountInfo[accountID] = personalInfo

  2. replace self.accountInfo[accountID].append(personalInfo) with self.accountInfo[accountID] = personalInfo


But if you understand the reference concept,




  1. keep self.accountInfo[accountID] = personalInfo

  2. remove self.accountInfo[accountID].append(personalInfo)
    Should also work!


But the latter way is discouraged as it is less readable.






share|improve this answer
























  • Thank you for your help :) Also, wouldn't either of the instructions you provided do the same thing? I don't mean as far as output because they obviously give the same output, but just overall writing that code would give you the same written reference?

    – H4MMY
    Nov 23 '18 at 19:56



















0














I think you mean



self.accountInfo[accountID].append(personalInfo)


to be



self.accountInfo[accountID] = personalInfo


you also don't need the latter line earlier in the code.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53440155%2fpython-at-end-of-list%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    To understand what exactly happened, you need to know about references.



    >>> a = 
    >>> test['a'] = a
    >>> a.append(1)
    >>> a.append(2)
    >>> test['a']
    [1, 2]


    When you did the line self.accountInfo[accountID] = personalInfo
    What it actually did was pass the reference of personalInfo to self.accountInfo[accountID]



    Meaning modifying personalInfo will also reflect in self.accountInfo[accountID]



    self.accountInfo[accountID] = personalInfo >> {'a92ab2fcea': }

    personalInfo.append(firstName) >> {'a92ab2fcea': ['firstName']} # Note: Since personalInfo changed, so self.accountInfo[accountID] also changed.

    personalInfo.append(lastName) >> {'a92ab2fcea': ['firstName','lastName']}

    personalInfo.append(email) >> {'a92ab2fcea': ['firstName','lastName','email']}

    personalInfo.append(password) >> {'a92ab2fcea': ['firstName','lastName','email','password']}

    personalInfo.append(birthdate) >> {'a92ab2fcea': ['firstName','lastName','email','password','birthdate']}

    personalInfo.append(alias) >> {'a92ab2fcea': ['firstName','lastName','email','password','birthdate','alias']}

    self.accountInfo[accountID].append(personalInfo) >> {'a92ab2fcea': ['firstName', 'lastName', 'email', 'password', 'birthdate', 'alias', [...]]} # What you are doing is appending personalInfo to personalInfo


    What I think you meant to do is:




    1. remove self.accountInfo[accountID] = personalInfo

    2. replace self.accountInfo[accountID].append(personalInfo) with self.accountInfo[accountID] = personalInfo


    But if you understand the reference concept,




    1. keep self.accountInfo[accountID] = personalInfo

    2. remove self.accountInfo[accountID].append(personalInfo)
      Should also work!


    But the latter way is discouraged as it is less readable.






    share|improve this answer
























    • Thank you for your help :) Also, wouldn't either of the instructions you provided do the same thing? I don't mean as far as output because they obviously give the same output, but just overall writing that code would give you the same written reference?

      – H4MMY
      Nov 23 '18 at 19:56
















    0














    To understand what exactly happened, you need to know about references.



    >>> a = 
    >>> test['a'] = a
    >>> a.append(1)
    >>> a.append(2)
    >>> test['a']
    [1, 2]


    When you did the line self.accountInfo[accountID] = personalInfo
    What it actually did was pass the reference of personalInfo to self.accountInfo[accountID]



    Meaning modifying personalInfo will also reflect in self.accountInfo[accountID]



    self.accountInfo[accountID] = personalInfo >> {'a92ab2fcea': }

    personalInfo.append(firstName) >> {'a92ab2fcea': ['firstName']} # Note: Since personalInfo changed, so self.accountInfo[accountID] also changed.

    personalInfo.append(lastName) >> {'a92ab2fcea': ['firstName','lastName']}

    personalInfo.append(email) >> {'a92ab2fcea': ['firstName','lastName','email']}

    personalInfo.append(password) >> {'a92ab2fcea': ['firstName','lastName','email','password']}

    personalInfo.append(birthdate) >> {'a92ab2fcea': ['firstName','lastName','email','password','birthdate']}

    personalInfo.append(alias) >> {'a92ab2fcea': ['firstName','lastName','email','password','birthdate','alias']}

    self.accountInfo[accountID].append(personalInfo) >> {'a92ab2fcea': ['firstName', 'lastName', 'email', 'password', 'birthdate', 'alias', [...]]} # What you are doing is appending personalInfo to personalInfo


    What I think you meant to do is:




    1. remove self.accountInfo[accountID] = personalInfo

    2. replace self.accountInfo[accountID].append(personalInfo) with self.accountInfo[accountID] = personalInfo


    But if you understand the reference concept,




    1. keep self.accountInfo[accountID] = personalInfo

    2. remove self.accountInfo[accountID].append(personalInfo)
      Should also work!


    But the latter way is discouraged as it is less readable.






    share|improve this answer
























    • Thank you for your help :) Also, wouldn't either of the instructions you provided do the same thing? I don't mean as far as output because they obviously give the same output, but just overall writing that code would give you the same written reference?

      – H4MMY
      Nov 23 '18 at 19:56














    0












    0








    0







    To understand what exactly happened, you need to know about references.



    >>> a = 
    >>> test['a'] = a
    >>> a.append(1)
    >>> a.append(2)
    >>> test['a']
    [1, 2]


    When you did the line self.accountInfo[accountID] = personalInfo
    What it actually did was pass the reference of personalInfo to self.accountInfo[accountID]



    Meaning modifying personalInfo will also reflect in self.accountInfo[accountID]



    self.accountInfo[accountID] = personalInfo >> {'a92ab2fcea': }

    personalInfo.append(firstName) >> {'a92ab2fcea': ['firstName']} # Note: Since personalInfo changed, so self.accountInfo[accountID] also changed.

    personalInfo.append(lastName) >> {'a92ab2fcea': ['firstName','lastName']}

    personalInfo.append(email) >> {'a92ab2fcea': ['firstName','lastName','email']}

    personalInfo.append(password) >> {'a92ab2fcea': ['firstName','lastName','email','password']}

    personalInfo.append(birthdate) >> {'a92ab2fcea': ['firstName','lastName','email','password','birthdate']}

    personalInfo.append(alias) >> {'a92ab2fcea': ['firstName','lastName','email','password','birthdate','alias']}

    self.accountInfo[accountID].append(personalInfo) >> {'a92ab2fcea': ['firstName', 'lastName', 'email', 'password', 'birthdate', 'alias', [...]]} # What you are doing is appending personalInfo to personalInfo


    What I think you meant to do is:




    1. remove self.accountInfo[accountID] = personalInfo

    2. replace self.accountInfo[accountID].append(personalInfo) with self.accountInfo[accountID] = personalInfo


    But if you understand the reference concept,




    1. keep self.accountInfo[accountID] = personalInfo

    2. remove self.accountInfo[accountID].append(personalInfo)
      Should also work!


    But the latter way is discouraged as it is less readable.






    share|improve this answer













    To understand what exactly happened, you need to know about references.



    >>> a = 
    >>> test['a'] = a
    >>> a.append(1)
    >>> a.append(2)
    >>> test['a']
    [1, 2]


    When you did the line self.accountInfo[accountID] = personalInfo
    What it actually did was pass the reference of personalInfo to self.accountInfo[accountID]



    Meaning modifying personalInfo will also reflect in self.accountInfo[accountID]



    self.accountInfo[accountID] = personalInfo >> {'a92ab2fcea': }

    personalInfo.append(firstName) >> {'a92ab2fcea': ['firstName']} # Note: Since personalInfo changed, so self.accountInfo[accountID] also changed.

    personalInfo.append(lastName) >> {'a92ab2fcea': ['firstName','lastName']}

    personalInfo.append(email) >> {'a92ab2fcea': ['firstName','lastName','email']}

    personalInfo.append(password) >> {'a92ab2fcea': ['firstName','lastName','email','password']}

    personalInfo.append(birthdate) >> {'a92ab2fcea': ['firstName','lastName','email','password','birthdate']}

    personalInfo.append(alias) >> {'a92ab2fcea': ['firstName','lastName','email','password','birthdate','alias']}

    self.accountInfo[accountID].append(personalInfo) >> {'a92ab2fcea': ['firstName', 'lastName', 'email', 'password', 'birthdate', 'alias', [...]]} # What you are doing is appending personalInfo to personalInfo


    What I think you meant to do is:




    1. remove self.accountInfo[accountID] = personalInfo

    2. replace self.accountInfo[accountID].append(personalInfo) with self.accountInfo[accountID] = personalInfo


    But if you understand the reference concept,




    1. keep self.accountInfo[accountID] = personalInfo

    2. remove self.accountInfo[accountID].append(personalInfo)
      Should also work!


    But the latter way is discouraged as it is less readable.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 23 '18 at 3:40









    PaltonPalton

    16




    16













    • Thank you for your help :) Also, wouldn't either of the instructions you provided do the same thing? I don't mean as far as output because they obviously give the same output, but just overall writing that code would give you the same written reference?

      – H4MMY
      Nov 23 '18 at 19:56



















    • Thank you for your help :) Also, wouldn't either of the instructions you provided do the same thing? I don't mean as far as output because they obviously give the same output, but just overall writing that code would give you the same written reference?

      – H4MMY
      Nov 23 '18 at 19:56

















    Thank you for your help :) Also, wouldn't either of the instructions you provided do the same thing? I don't mean as far as output because they obviously give the same output, but just overall writing that code would give you the same written reference?

    – H4MMY
    Nov 23 '18 at 19:56





    Thank you for your help :) Also, wouldn't either of the instructions you provided do the same thing? I don't mean as far as output because they obviously give the same output, but just overall writing that code would give you the same written reference?

    – H4MMY
    Nov 23 '18 at 19:56













    0














    I think you mean



    self.accountInfo[accountID].append(personalInfo)


    to be



    self.accountInfo[accountID] = personalInfo


    you also don't need the latter line earlier in the code.






    share|improve this answer




























      0














      I think you mean



      self.accountInfo[accountID].append(personalInfo)


      to be



      self.accountInfo[accountID] = personalInfo


      you also don't need the latter line earlier in the code.






      share|improve this answer


























        0












        0








        0







        I think you mean



        self.accountInfo[accountID].append(personalInfo)


        to be



        self.accountInfo[accountID] = personalInfo


        you also don't need the latter line earlier in the code.






        share|improve this answer













        I think you mean



        self.accountInfo[accountID].append(personalInfo)


        to be



        self.accountInfo[accountID] = personalInfo


        you also don't need the latter line earlier in the code.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 '18 at 3:16









        pooh17pooh17

        444




        444






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53440155%2fpython-at-end-of-list%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            RAC Tourist Trophy