Python: […] at End of List
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
add a comment |
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
1
The Ellipses indicates a recursively defined structure. In your cases you have appended the list to itself.
– Klaus D.
Nov 23 at 3:07
add a comment |
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
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
python list dictionary
asked Nov 23 at 2:57
H4MMY
36
36
1
The Ellipses indicates a recursively defined structure. In your cases you have appended the list to itself.
– Klaus D.
Nov 23 at 3:07
add a comment |
1
The Ellipses indicates a recursively defined structure. In your cases you have appended the list to itself.
– Klaus D.
Nov 23 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 at 3:07
The Ellipses indicates a recursively defined structure. In your cases you have appended the list to itself.
– Klaus D.
Nov 23 at 3:07
add a comment |
2 Answers
2
active
oldest
votes
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:
- remove
self.accountInfo[accountID] = personalInfo
- replace
self.accountInfo[accountID].append(personalInfo) with self.accountInfo[accountID] = personalInfo
But if you understand the reference concept,
- keep
self.accountInfo[accountID] = personalInfo
- remove
self.accountInfo[accountID].append(personalInfo)
Should also work!
But the latter way is discouraged as it is less readable.
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 at 19:56
add a comment |
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.
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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:
- remove
self.accountInfo[accountID] = personalInfo
- replace
self.accountInfo[accountID].append(personalInfo) with self.accountInfo[accountID] = personalInfo
But if you understand the reference concept,
- keep
self.accountInfo[accountID] = personalInfo
- remove
self.accountInfo[accountID].append(personalInfo)
Should also work!
But the latter way is discouraged as it is less readable.
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 at 19:56
add a comment |
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:
- remove
self.accountInfo[accountID] = personalInfo
- replace
self.accountInfo[accountID].append(personalInfo) with self.accountInfo[accountID] = personalInfo
But if you understand the reference concept,
- keep
self.accountInfo[accountID] = personalInfo
- remove
self.accountInfo[accountID].append(personalInfo)
Should also work!
But the latter way is discouraged as it is less readable.
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 at 19:56
add a comment |
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:
- remove
self.accountInfo[accountID] = personalInfo
- replace
self.accountInfo[accountID].append(personalInfo) with self.accountInfo[accountID] = personalInfo
But if you understand the reference concept,
- keep
self.accountInfo[accountID] = personalInfo
- remove
self.accountInfo[accountID].append(personalInfo)
Should also work!
But the latter way is discouraged as it is less readable.
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:
- remove
self.accountInfo[accountID] = personalInfo
- replace
self.accountInfo[accountID].append(personalInfo) with self.accountInfo[accountID] = personalInfo
But if you understand the reference concept,
- keep
self.accountInfo[accountID] = personalInfo
- remove
self.accountInfo[accountID].append(personalInfo)
Should also work!
But the latter way is discouraged as it is less readable.
answered Nov 23 at 3:40
Palton
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 at 19:56
add a comment |
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 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 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 at 19:56
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 23 at 3:16
pooh17
444
444
add a comment |
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
The Ellipses indicates a recursively defined structure. In your cases you have appended the list to itself.
– Klaus D.
Nov 23 at 3:07