Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

list of dicts

# import library
from typing import List, Dict
  
# define function
def get_list_of_dicts(name: str, category: str) -> Dict[str, str]:
    return [{'name': name, 'category': category}]
  
Fruit = ["Mango", "tomato", "potato", "papaya"]
Fruit_type = ["fruit", "vegetable", "vegetable", "fruit"]
  
res = [get_list_of_dicts(Fruit[i], Fruit_type[i]) for i in range(3)]
  
print(res)
Comment

python list of dictionaries

  new_player1 = { 'firstName': 'LaMarcus', 'lastName': 'Aldridge', 'jersey': '12', 'heightMeters': '2.11', 'nbaDebutYear': '2006', 'weightKilograms': '117.9'}
            new_player2 = { 'firstName': 'LeBron', 'lastName': 'James', 'jersey': '2', 'heightMeters': '2.03', 'nbaDebutYear': '2003', 'weightKilograms': '113.4' }
            new_player3 = { 'firstName': 'Kawhi', 'lastName': 'Leonard', 'jersey': '2', 'heightMeters': '2.01', 'nbaDebutYear': '2011', 'weightKilograms': '104.3' }  
  
  nba_players = []
  nba_players.append(player)
  nba_players.append(new_player1)
  nba_players.append(new_player2)
  nba_players.append(new_player3)
Comment

python list of dictionaries to list

[d['value'] for d in l]
Comment

python list of dictionaries

lst = [{'a':0,'b':1,'c':2},
       {'d':3,'c':4,'b':5},
       {'a':5,'d':6,'e':1}]

print(lst[1])
print(lst[1]['c'])
Comment

python list of dictionaries to list

[d['value'] for d in l if 'value' in d]
Comment

PREVIOUS NEXT
Code Example
Python :: python crash course 
Python :: python lambda function if else 
Python :: length of int in python 
Python :: py string in list 
Python :: python list replace nan with 0 
Python :: adding debugger in django code 
Python :: how to hide ticks marks in plot 
Python :: spanish to english 
Python :: selenium python get element by type 
Python :: decode multipart/form-data python lambda 
Python :: change data type python 
Python :: cv2.imwrite 
Python :: install python windows powershell 
Python :: how to define functions in python 
Python :: discord.py message user 
Python :: check django version windows 
Python :: how to draw a single pixel in pyglet 
Python :: django jinja else if template tags 
Python :: random letters generator python 
Python :: python json write utf 8 
Python :: django rest framework function based views 
Python :: Change Python interpreter in pycharm 
Python :: django dumpdata specific app 
Python :: get key from value dictionary py 
Python :: urllib.request.urlopen with headers 
Python :: pandas count number of repetitions of each diferent value 
Python :: how to remove a letter from a string python 
Python :: collections counter sort by value 
Python :: np.exp in python numpy 
Python :: streamlit sidebar width 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =