Convert a list to dictionary without extra curly brackets being addedHow do I merge a list of dicts into a single dict?How do you sort a dictionary by value?How do I sort a list of dictionaries by a value of the dictionary?Convert two lists into a dictionary in PythonPython creating a dictionary of listsConvert a String representation of a Dictionary to a dictionary?Create a dictionary with list comprehension in PythonUse of *args and **kwargsConvert a list to a dictionary in PythonPython Dictionary ComprehensionHow to return dictionary keys as a list in Python?
USPS Back Room - Trespassing?
Creating second map without labels using QGIS?
Dad jokes are fun
Why did Jon Snow admit his fault in S08E06?
Is keeping the forking link on a true fork necessary (Github/GPL)?
What is the use case for non-breathable waterproof pants?
Why is this integration method not valid?
Why does splatting create a tuple on the rhs but a list on the lhs?
Expected maximum number of unpaired socks
How was Daenerys able to legitimise Gendry?
Is this homebrew "Cactus Grenade" cantrip balanced?
The disk image is 497GB smaller than the target device
Count all vowels in string
Can a ring of spell storing and access to Find spells produce an endless menagerie?
Why did it take so long for Germany to allow electric scooters / e-rollers on the roads?
Freedom of Speech and Assembly in China
What did the 'turbo' button actually do?
Navigating a quick return to previous employer
How to melt snow without fire or using body heat?
Using too much dialogue?
Is it legal to have an abortion in another state or abroad?
What could a self-sustaining lunar colony slowly lose that would ultimately prove fatal?
Do copyright notices need to be placed at the beginning of a file?
How to keep consistency across the application architecture as a team grows?
Convert a list to dictionary without extra curly brackets being added
How do I merge a list of dicts into a single dict?How do you sort a dictionary by value?How do I sort a list of dictionaries by a value of the dictionary?Convert two lists into a dictionary in PythonPython creating a dictionary of listsConvert a String representation of a Dictionary to a dictionary?Create a dictionary with list comprehension in PythonUse of *args and **kwargsConvert a list to a dictionary in PythonPython Dictionary ComprehensionHow to return dictionary keys as a list in Python?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
Say I have a list like this:
alist = ['key': 'value']
And then I convert it to a dictionary like this
adict = dict(alist)
The formatting becomes
'''key: 'value'
This makes it so I can't access the data from the dictionary. Is there a way to convert the list to a dictionary without there being extra ' ' -- brackets and single quotes
python dictionary
add a comment |
Say I have a list like this:
alist = ['key': 'value']
And then I convert it to a dictionary like this
adict = dict(alist)
The formatting becomes
'''key: 'value'
This makes it so I can't access the data from the dictionary. Is there a way to convert the list to a dictionary without there being extra ' ' -- brackets and single quotes
python dictionary
1
The code you posted does not run without exceptions. It does not produce the output you posted. Please check again.
– Markus Unterwaditzer
Mar 23 at 23:41
Possible duplicate of How do I merge a list of dicts into a single dict?
– Michael Doubez
Mar 23 at 23:45
adict = alist[0]
should do it.
– martineau
Mar 24 at 2:18
add a comment |
Say I have a list like this:
alist = ['key': 'value']
And then I convert it to a dictionary like this
adict = dict(alist)
The formatting becomes
'''key: 'value'
This makes it so I can't access the data from the dictionary. Is there a way to convert the list to a dictionary without there being extra ' ' -- brackets and single quotes
python dictionary
Say I have a list like this:
alist = ['key': 'value']
And then I convert it to a dictionary like this
adict = dict(alist)
The formatting becomes
'''key: 'value'
This makes it so I can't access the data from the dictionary. Is there a way to convert the list to a dictionary without there being extra ' ' -- brackets and single quotes
python dictionary
python dictionary
edited Mar 24 at 2:18
martineau
71.7k1093190
71.7k1093190
asked Mar 23 at 23:35
the_martianthe_martian
352216
352216
1
The code you posted does not run without exceptions. It does not produce the output you posted. Please check again.
– Markus Unterwaditzer
Mar 23 at 23:41
Possible duplicate of How do I merge a list of dicts into a single dict?
– Michael Doubez
Mar 23 at 23:45
adict = alist[0]
should do it.
– martineau
Mar 24 at 2:18
add a comment |
1
The code you posted does not run without exceptions. It does not produce the output you posted. Please check again.
– Markus Unterwaditzer
Mar 23 at 23:41
Possible duplicate of How do I merge a list of dicts into a single dict?
– Michael Doubez
Mar 23 at 23:45
adict = alist[0]
should do it.
– martineau
Mar 24 at 2:18
1
1
The code you posted does not run without exceptions. It does not produce the output you posted. Please check again.
– Markus Unterwaditzer
Mar 23 at 23:41
The code you posted does not run without exceptions. It does not produce the output you posted. Please check again.
– Markus Unterwaditzer
Mar 23 at 23:41
Possible duplicate of How do I merge a list of dicts into a single dict?
– Michael Doubez
Mar 23 at 23:45
Possible duplicate of How do I merge a list of dicts into a single dict?
– Michael Doubez
Mar 23 at 23:45
adict = alist[0]
should do it.– martineau
Mar 24 at 2:18
adict = alist[0]
should do it.– martineau
Mar 24 at 2:18
add a comment |
3 Answers
3
active
oldest
votes
You can use the index 0
to avoid the extra
braces because the dictionary can be accessed as alist[0]
. Moreover, you do not need dict
additionally because your list content is already a dictionary
adict = alist[0]
Now you get the desired behavior
print (adict)
# 'key': 'value'
@DeveshKumarSingh: It works for me. Anyway,dict
is not need here because the list contains already a dictionary. Check my edit
– Sheldore
Mar 23 at 23:41
add a comment |
If you first structure your list by swapping the curly braces, you won't have any issues using this :)
dict([('A', 1), ('B', 2), ('C', 3)])
add a comment |
If your objective is to initialise a dictionary object with a key value pair (or a bunch of key value pairs), why would you use a list first?
You could simple write
adict = 'key': 'value', 'Hello': 'world'
print(adict)
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%2f55319366%2fconvert-a-list-to-dictionary-without-extra-curly-brackets-being-added%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use the index 0
to avoid the extra
braces because the dictionary can be accessed as alist[0]
. Moreover, you do not need dict
additionally because your list content is already a dictionary
adict = alist[0]
Now you get the desired behavior
print (adict)
# 'key': 'value'
@DeveshKumarSingh: It works for me. Anyway,dict
is not need here because the list contains already a dictionary. Check my edit
– Sheldore
Mar 23 at 23:41
add a comment |
You can use the index 0
to avoid the extra
braces because the dictionary can be accessed as alist[0]
. Moreover, you do not need dict
additionally because your list content is already a dictionary
adict = alist[0]
Now you get the desired behavior
print (adict)
# 'key': 'value'
@DeveshKumarSingh: It works for me. Anyway,dict
is not need here because the list contains already a dictionary. Check my edit
– Sheldore
Mar 23 at 23:41
add a comment |
You can use the index 0
to avoid the extra
braces because the dictionary can be accessed as alist[0]
. Moreover, you do not need dict
additionally because your list content is already a dictionary
adict = alist[0]
Now you get the desired behavior
print (adict)
# 'key': 'value'
You can use the index 0
to avoid the extra
braces because the dictionary can be accessed as alist[0]
. Moreover, you do not need dict
additionally because your list content is already a dictionary
adict = alist[0]
Now you get the desired behavior
print (adict)
# 'key': 'value'
edited Mar 23 at 23:39
answered Mar 23 at 23:37
SheldoreSheldore
17.4k31330
17.4k31330
@DeveshKumarSingh: It works for me. Anyway,dict
is not need here because the list contains already a dictionary. Check my edit
– Sheldore
Mar 23 at 23:41
add a comment |
@DeveshKumarSingh: It works for me. Anyway,dict
is not need here because the list contains already a dictionary. Check my edit
– Sheldore
Mar 23 at 23:41
@DeveshKumarSingh: It works for me. Anyway,
dict
is not need here because the list contains already a dictionary. Check my edit– Sheldore
Mar 23 at 23:41
@DeveshKumarSingh: It works for me. Anyway,
dict
is not need here because the list contains already a dictionary. Check my edit– Sheldore
Mar 23 at 23:41
add a comment |
If you first structure your list by swapping the curly braces, you won't have any issues using this :)
dict([('A', 1), ('B', 2), ('C', 3)])
add a comment |
If you first structure your list by swapping the curly braces, you won't have any issues using this :)
dict([('A', 1), ('B', 2), ('C', 3)])
add a comment |
If you first structure your list by swapping the curly braces, you won't have any issues using this :)
dict([('A', 1), ('B', 2), ('C', 3)])
If you first structure your list by swapping the curly braces, you won't have any issues using this :)
dict([('A', 1), ('B', 2), ('C', 3)])
answered Mar 23 at 23:40
David SilveiroDavid Silveiro
595518
595518
add a comment |
add a comment |
If your objective is to initialise a dictionary object with a key value pair (or a bunch of key value pairs), why would you use a list first?
You could simple write
adict = 'key': 'value', 'Hello': 'world'
print(adict)
add a comment |
If your objective is to initialise a dictionary object with a key value pair (or a bunch of key value pairs), why would you use a list first?
You could simple write
adict = 'key': 'value', 'Hello': 'world'
print(adict)
add a comment |
If your objective is to initialise a dictionary object with a key value pair (or a bunch of key value pairs), why would you use a list first?
You could simple write
adict = 'key': 'value', 'Hello': 'world'
print(adict)
If your objective is to initialise a dictionary object with a key value pair (or a bunch of key value pairs), why would you use a list first?
You could simple write
adict = 'key': 'value', 'Hello': 'world'
print(adict)
answered Mar 23 at 23:43
GroGro
50549
50549
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.
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%2f55319366%2fconvert-a-list-to-dictionary-without-extra-curly-brackets-being-added%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 code you posted does not run without exceptions. It does not produce the output you posted. Please check again.
– Markus Unterwaditzer
Mar 23 at 23:41
Possible duplicate of How do I merge a list of dicts into a single dict?
– Michael Doubez
Mar 23 at 23:45
adict = alist[0]
should do it.– martineau
Mar 24 at 2:18