Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 12-07-2018, 06:24 AM   #1
Registered: Aug 2005
Location: Manchester, England
Distribution: Ubuntu 18.10
Posts: 338

Rep: Reputation: 25
Find value in list of dictionaries in Python3

I have the following and have been having difficulty finding the values I need in it.

tags=[[{'Key': 'Type', 'Value': 'Test'}], 
[{'Key': 'Type', 'Value': 'Test'}], 
[{'Key': 'Type', 'Value': 'Thing-Im-looking-for'}], 
[{'Key': 'Type', 'Value': 'Multi-Value'}]]
Any advice appreciated.
Old 12-07-2018, 07:01 AM   #2
LQ Guru
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 19 MATE
Posts: 6,429
Blog Entries: 2

Rep: Reputation: 2110Reputation: 2110Reputation: 2110Reputation: 2110Reputation: 2110Reputation: 2110Reputation: 2110Reputation: 2110Reputation: 2110Reputation: 2110Reputation: 2110
That is an interesting-looking Python structure. Essentially it is a list for which each element is itself a list containing only one element, a dictionary. Are you sure that this is best suited for what you're trying to do?

Could you explain in English what sort of data store you're trying to create and for what purposes?
2 members found this post helpful.
Old 12-07-2018, 10:21 AM   #3
Registered: Apr 2013
Location: Massachusetts
Distribution: Debian
Posts: 404

Rep: Reputation: 172Reputation: 172
$ python3
Python 3.2.3 (default, Mar 25 2017, 10:08:27) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> tags=[[{'Key': 'Type', 'Value': 'Test'}], 
... [{'Key': 'Type', 'Value': 'Test'}], 
... [{'Key': 'Type', 'Value': 'Thing-Im-looking-for'}], 
... [{'Key': 'Type', 'Value': 'Multi-Value'}]]
>>> tags[2][0]['Value']
>>> print(tags[2][0]['Value'])
>>> exit()
Edit: If you don't require the one-element lists, which hydrurga pointed out, you could remove the inner brackets and then you wouldn't need the [0] in the above code. Is that the nature of your difficulty?

Last edited by Beryllos; 12-07-2018 at 10:40 AM.
1 members found this post helpful.



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] making python3.6.4 default python3 Astral Axiom Linux - Newbie 17 04-14-2018 11:55 AM
[SOLVED] how to start python3.6 interpreter just by typing python in terminal not python3.6 bmohanraj91 Linux - Newbie 4 05-10-2017 08:51 AM
After upgrade python3.4 to python3.5.1 , not able to install packages "request" though pip3 YOGESHAS87 Linux - Software 1 08-03-2016 11:38 PM
strange value assignments variable = value, value?? ostrow30 Programming 2 07-24-2011 08:59 AM
difference between value *value and value * value PoleStar Linux - Newbie 1 11-26-2010 04:37 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:27 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration