Editing Python cheat sheet: Difference between revisions

From Coolscript
Jump to navigation Jump to search
(Created page with "=Two dimension dictionary with embedded arrays= #Init Dict dict = {} '''#Inventory for Category Fruits''' dict['1000A'] = {} dict['1000A']['Category'] = 'Fruits' dict['1000A']['Items'] = 'Orange, Lemmon, Apple' dict['1000A']['Location'] = 'New York' '''#Inventory for Category Cars''' dict['1000B'] = {} dict['1000B']['Category'] = 'Cars' dict['1000B']['Items'] = 'Audi, BMW, Mercedes, VW' dict['1000B']['Location'] = 'London' '''#Inventory for Category Bikes''...")
 
(Replaced content with "Please goto Python cheat sheet")
Tag: Replaced
 
Line 1: Line 1:
=Two dimension dictionary with embedded arrays=
Please goto Python cheat sheet
 
#Init Dict
dict = {}
'''#Inventory for Category Fruits'''
dict['1000A'] = {}
dict['1000A']['Category'] = 'Fruits'
dict['1000A']['Items'] = 'Orange, Lemmon, Apple'
dict['1000A']['Location'] = 'New York'
'''#Inventory for Category Cars'''
dict['1000B'] = {}
dict['1000B']['Category'] = 'Cars'
dict['1000B']['Items'] = 'Audi, BMW, Mercedes, VW'
dict['1000B']['Location'] = 'London'
'''#Inventory for Category Bikes'''
dict['1000C'] = {}
dict['1000C']['Category'] = 'Bikes'
dict['1000C']['Items'] = 'Ducati, KTM, Yamaha, Husquarna'
dict['1000C']['Location'] = 'Frankfurt'
#List the dict inventory
for pnt in dict:
    print("-ID", pnt)
    print("\t-Category", dict[pnt]['Category'])
    print("\t-Location", dict[pnt]['Location'])
    print("\t-Items:")
    '''#Split the dict[pnt]['Items'] string, then strip and map into the set named items'''
    items = map(str.strip, dict[pnt]['Items'].split(',')) #items contains now a set of dict[pnt]['Items']
    for item in items:
      print("\t\t-", item)
 
 
==Output==
 
-ID 1000A
        -Category Fruits
        -Location New York
        -Items:
                - Orange
                - Lemmon
                - Apple
-ID 1000B
        -Category Cars
        -Location London
        -Items:
                - Audi
                - BMW
                - Mercedes
                - VW
-ID 1000C
        -Category Bikes
        -Location Frankfurt
        -Items:
                - Ducati
                - KTM
                - Yamaha
                - Husquarna

Latest revision as of 21:13, 27 August 2024

Please goto Python cheat sheet