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

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

PREVIOUS NEXT
Code Example
Python :: how to get python list length 
Python :: python cv2 canny overlay on image 
Python :: if condition dataframe python 
Python :: render() in django 
Python :: streamlit headings;streamlit text 
Python :: how to make text to speech in python 
Python :: multiline comment in python 
Python :: docker build python fastapi 
Python :: Python numpy.flatiter function Example 
Python :: create a django project 
Python :: os.getcwd() python 3 
Python :: kivy dropdown list 
Python :: python generate set of random numbers 
Python :: how to import and use keyboard with pygame 
Python :: how to get user input python 
Python :: turn columns into one column as list python 
Python :: python print all variables in memory 
Python :: pandas apply check for string length in column 
Python :: sequenza di fibonacci python 
Python :: Setting spacing between ticks in matplotlib 
Python :: np reshape 
Python :: python cast to float 
Python :: python requests no certificate example 
Python :: python test type 
Python :: map python 3 
Python :: radians in python turtle 
Python :: python format strings 
Python :: foreignkey as users from a user group django 
Python :: terminal output redirect to a file 
Python :: python all permutations of a string 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =