Can a single word 'string' be converted into a dictionary of the same nameFlattening a dictionary into a...
How would one buy a used TIE Fighter or X-Wing?
Overfitting and Underfitting
Why zero tolerance on nudity in space?
En Passant For Beginners
Unwarranted claim of higher degree of accuracy in zircon geochronology
If I delete my router's history can my ISP still provide it to my parents?
Can pricing be copyrighted?
Everyone is beautiful
How to generate a matrix with certain conditions
Is there a better way to make this?
What is the wife of a henpecked husband called?
How to remove trailing forward slash
Quenching swords in dragon blood; why?
How do you funnel food off a cutting board?
Is there any differences between “gucken” and “schauen”?
Would a National Army of mercenaries be a feasible idea?
Word or phrase for showing great skill at something without formal training in it
Finding radius of circle
Does Windows 10's telemetry include sending *.doc files if Word crashed?
just upgraded iMac late 2015 ram from 12 GB to 28 GB and it became too slow to use
Can we use the stored gravitational potential energy of a building to produce power?
Using loops to create tables
How to deal with an incendiary email that was recalled
What do you call a fact that doesn't match the settings?
Can a single word 'string' be converted into a dictionary of the same name
Flattening a dictionary into a stringString Matching and Clusteringmore elegant way when call parent method with the same nameAutocomplete Trie OptimizationConvert a string into a dictionaryGrouping the results in an array having same nameBreak a full name into a dictionary of its partsHomogeneousDict - The Python dictionary that can have homogeneous keysDictrie: Extending the Python dictionary into a TrieDetermine all ways a string can be split into valid words, given a dictionary of all words
$begingroup$
Can a single word 'string' be converted into a dictionary of the same name?
My program begins with a list of names. eg: 'Bob','John','Mike'
This list is then shuffled into a random order. eg: ['Mike','Bob','John']
A name then gets taken from the list. eg: ['Mike'] leaving ['Bob','John']
I would then like to associate this string with a dictionary of the same name.
eg: 'Mike' = {'Surname' : 'Jones', 'Age': 55, 'Staff ID': 101}
Then be able to call and print a particular Key : Value of the chosen name.
eg: print(Mike[Age])
(my code at present is similar to this example)
list_of_names = ['Bob','John','Mary','Joan','Mike']
chosen_name = list_of_names.pop(0)
print("person chosen: ", (chosen_name))
# Dictionaries are pre-formatted waiting to be paired with their listed name
'Bob' = {'Surname' : 'Kelly', 'Age': 49, 'Staff ID': 86},
'John' = {'Surname' : 'Hogan', 'Age': 57, 'Staff ID': 22},
'Mike' = {'Surname' : 'Jones', 'Age': 55, 'Staff ID': 101},
# Prints the randomly chosen name and the dictionary associated with it.
print(chosen_name)
# Prints a Value for a particular key of that chosen name
print(chosen_name[key])
I would greatly appreciate any advice or even alternative methods of achieving this.
Many thanks.
python dictionary
New contributor
$endgroup$
add a comment |
$begingroup$
Can a single word 'string' be converted into a dictionary of the same name?
My program begins with a list of names. eg: 'Bob','John','Mike'
This list is then shuffled into a random order. eg: ['Mike','Bob','John']
A name then gets taken from the list. eg: ['Mike'] leaving ['Bob','John']
I would then like to associate this string with a dictionary of the same name.
eg: 'Mike' = {'Surname' : 'Jones', 'Age': 55, 'Staff ID': 101}
Then be able to call and print a particular Key : Value of the chosen name.
eg: print(Mike[Age])
(my code at present is similar to this example)
list_of_names = ['Bob','John','Mary','Joan','Mike']
chosen_name = list_of_names.pop(0)
print("person chosen: ", (chosen_name))
# Dictionaries are pre-formatted waiting to be paired with their listed name
'Bob' = {'Surname' : 'Kelly', 'Age': 49, 'Staff ID': 86},
'John' = {'Surname' : 'Hogan', 'Age': 57, 'Staff ID': 22},
'Mike' = {'Surname' : 'Jones', 'Age': 55, 'Staff ID': 101},
# Prints the randomly chosen name and the dictionary associated with it.
print(chosen_name)
# Prints a Value for a particular key of that chosen name
print(chosen_name[key])
I would greatly appreciate any advice or even alternative methods of achieving this.
Many thanks.
python dictionary
New contributor
$endgroup$
$begingroup$
Just put the dictionaries into another dictionary with the names as the keys. Note though, Code Review is for improving working code. This would be more appropriate for Stack Overflow, but I suspect this has been asked already.
$endgroup$
– Carcigenicate
3 mins ago
add a comment |
$begingroup$
Can a single word 'string' be converted into a dictionary of the same name?
My program begins with a list of names. eg: 'Bob','John','Mike'
This list is then shuffled into a random order. eg: ['Mike','Bob','John']
A name then gets taken from the list. eg: ['Mike'] leaving ['Bob','John']
I would then like to associate this string with a dictionary of the same name.
eg: 'Mike' = {'Surname' : 'Jones', 'Age': 55, 'Staff ID': 101}
Then be able to call and print a particular Key : Value of the chosen name.
eg: print(Mike[Age])
(my code at present is similar to this example)
list_of_names = ['Bob','John','Mary','Joan','Mike']
chosen_name = list_of_names.pop(0)
print("person chosen: ", (chosen_name))
# Dictionaries are pre-formatted waiting to be paired with their listed name
'Bob' = {'Surname' : 'Kelly', 'Age': 49, 'Staff ID': 86},
'John' = {'Surname' : 'Hogan', 'Age': 57, 'Staff ID': 22},
'Mike' = {'Surname' : 'Jones', 'Age': 55, 'Staff ID': 101},
# Prints the randomly chosen name and the dictionary associated with it.
print(chosen_name)
# Prints a Value for a particular key of that chosen name
print(chosen_name[key])
I would greatly appreciate any advice or even alternative methods of achieving this.
Many thanks.
python dictionary
New contributor
$endgroup$
Can a single word 'string' be converted into a dictionary of the same name?
My program begins with a list of names. eg: 'Bob','John','Mike'
This list is then shuffled into a random order. eg: ['Mike','Bob','John']
A name then gets taken from the list. eg: ['Mike'] leaving ['Bob','John']
I would then like to associate this string with a dictionary of the same name.
eg: 'Mike' = {'Surname' : 'Jones', 'Age': 55, 'Staff ID': 101}
Then be able to call and print a particular Key : Value of the chosen name.
eg: print(Mike[Age])
(my code at present is similar to this example)
list_of_names = ['Bob','John','Mary','Joan','Mike']
chosen_name = list_of_names.pop(0)
print("person chosen: ", (chosen_name))
# Dictionaries are pre-formatted waiting to be paired with their listed name
'Bob' = {'Surname' : 'Kelly', 'Age': 49, 'Staff ID': 86},
'John' = {'Surname' : 'Hogan', 'Age': 57, 'Staff ID': 22},
'Mike' = {'Surname' : 'Jones', 'Age': 55, 'Staff ID': 101},
# Prints the randomly chosen name and the dictionary associated with it.
print(chosen_name)
# Prints a Value for a particular key of that chosen name
print(chosen_name[key])
I would greatly appreciate any advice or even alternative methods of achieving this.
Many thanks.
python dictionary
python dictionary
New contributor
New contributor
edited 3 mins ago
Learn English China
New contributor
asked 9 mins ago
Learn English ChinaLearn English China
1
1
New contributor
New contributor
$begingroup$
Just put the dictionaries into another dictionary with the names as the keys. Note though, Code Review is for improving working code. This would be more appropriate for Stack Overflow, but I suspect this has been asked already.
$endgroup$
– Carcigenicate
3 mins ago
add a comment |
$begingroup$
Just put the dictionaries into another dictionary with the names as the keys. Note though, Code Review is for improving working code. This would be more appropriate for Stack Overflow, but I suspect this has been asked already.
$endgroup$
– Carcigenicate
3 mins ago
$begingroup$
Just put the dictionaries into another dictionary with the names as the keys. Note though, Code Review is for improving working code. This would be more appropriate for Stack Overflow, but I suspect this has been asked already.
$endgroup$
– Carcigenicate
3 mins ago
$begingroup$
Just put the dictionaries into another dictionary with the names as the keys. Note though, Code Review is for improving working code. This would be more appropriate for Stack Overflow, but I suspect this has been asked already.
$endgroup$
– Carcigenicate
3 mins ago
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
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: "196"
};
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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
});
}
});
Learn English China is a new contributor. Be nice, and check out our Code of Conduct.
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%2fcodereview.stackexchange.com%2fquestions%2f214617%2fcan-a-single-word-string-be-converted-into-a-dictionary-of-the-same-name%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Learn English China is a new contributor. Be nice, and check out our Code of Conduct.
Learn English China is a new contributor. Be nice, and check out our Code of Conduct.
Learn English China is a new contributor. Be nice, and check out our Code of Conduct.
Learn English China is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Code Review Stack Exchange!
- 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.
Use MathJax to format equations. MathJax reference.
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%2fcodereview.stackexchange.com%2fquestions%2f214617%2fcan-a-single-word-string-be-converted-into-a-dictionary-of-the-same-name%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
$begingroup$
Just put the dictionaries into another dictionary with the names as the keys. Note though, Code Review is for improving working code. This would be more appropriate for Stack Overflow, but I suspect this has been asked already.
$endgroup$
– Carcigenicate
3 mins ago