Question

In python Create a function that will take in an argument ( a 2D list of strings). The function will return a dictionary wher

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1 def main(): listone-[] #list create matrix (listone) #create matrix function 2 print(listone ,end-) #printing listone f

def main():
   listOne=[] #list
   create_matrix(listOne) #create matrix function
  
   print("listOne= ",end='') #printing listOne
   for i in listOne: #iterates through each list in listOne
       print(i,",",sep='',end='\n\t') #printing list
  
   dic={} #dictionary
   for i in range(0,len(listOne)): #iterates loop from 0 , length of each row
       a=[]
       for j in range(1,len(listOne[i])): #iterates length of column times
           a.append(listOne[i][j]) #adds the elements to list except first element
       dic[listOne[i][0]]=a #creates dictionary element
  
   print("\nDictionary: ")
   for i in dic: #iterates through each key in dictionary
       print(i,":",dic[i],sep='')
  

def create_matrix(listOne):
   print("Enter elements (-1 to enter next row and 0 to exit the loop)")
   ele=input()
  
   while(ele!='0'): #if element is 0 stop the loop
       a=[]
       while(ele!='-1'): #if element is -1 then go to next row
           a.append(ele)
           ele=input()
       listOne.append(a)
       ele=input()

main()

jack@jack-TravelMate-P243-M:~$ python3 dict.py Enter elements (-1 to enter next row and 0 to exit the loop) aa bb CC dd -1 ee

Add a comment
Know the answer?
Add Answer to:
In python Create a function that will take in an argument ( a 2D list of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a function draw_T in functions.py, which receives three parameters: width, height and symbol. The first...

    Write a function draw_T in functions.py, which receives three parameters: width, height and symbol. The first two parameters are assumed to be integers and the third is a single character string. You don’t need to validate the type of the given parameters. The function returns no values. The function uses the given parameters to draw a T shape, such that the parameter width controls the upper bar, and height controls the middle vertical bar. The parameter symbol, controls which symbol...

  • Production-Costs. Quantity Total Fixed Cost Total Variable Cost Total Cost Average Fixed Cost Average Variable Cost...

    Production-Costs. Quantity Total Fixed Cost Total Variable Cost Total Cost Average Fixed Cost Average Variable Cost Average Total Cost Marginal Cost $25 FE FF LL MM GG $13.25 HH UU $16 BB 522 CC vy DD KK $22.75 ww Solve for the missing entries in the above table. Round all average cost calculations to the nearest cent

  • Using the following information below, fill out Table 1 for you. PTC: taster (T-), non-taster (tt)...

    Using the following information below, fill out Table 1 for you. PTC: taster (T-), non-taster (tt) Sodium benzoate: taster (B-), non-taster (bb) Hair type: Is your hair naturally wavy (CC), wavy (Cc), or straight (cc)? Hair color: Dark hair (DD or Dd) is dominant over light colored hair (dd) Widow's peak: the presence of a window's peak is dominant (WW or Ww) over absent (ww) Eyebrows: bushy (BB or Bb) dominant over fine (bb) Eye color: non-blue (EE or Ee)...

  • dd.) XS NBS CCM, A ee.) 1. fuming H2SO4 2. HNO3/H2SO4 3. Zn(Hg), HCI, A ff.)...

    dd.) XS NBS CCM, A ee.) 1. fuming H2SO4 2. HNO3/H2SO4 3. Zn(Hg), HCI, A ff.) OH 1. H.Cros/acetone 2. PrMgl/Et20 3. H30* gg.) HORS. NH2 SO3 H2SO4 hh.) OE 1. LAIH/Et20/ -78 °C 2. H20 ii.) 1. Li/Et, 2. Ph Co 3. H30* jj.) Br 1. Mg/THE 2. formaldehyde 3. NHCl(aq) kk.) 2 Na, EtOH, NH3 II.) CH3BF4 mm.) SOUH 2 Na, EtOH, NH3 nn.) NO2 H2SO4(conc) HNO3(conc) NO2 00.) 1. SO3, H2SO4 2. NaOH/KOHA 3. H30*

  • ​Tailwind, Inc., produces​ high-quality but expensive training shoes for runners. The Tailwind​ shoe, which sells for​...

    ​Tailwind, Inc., produces​ high-quality but expensive training shoes for runners. The Tailwind​ shoe, which sells for​ $210, contains both​ gas- and​ liquid-filled compartments to provide more stability and better protection against​ knee, foot, and back injuries. Manufacturing the shoes requires 10 separate tasks. There are 400400 minutes available for manufacturing the shoes in the plant each day. Daily demand is 6464. The information for the tasks is as​ follows:                                         Task Performance Time​ (mins) Predecessors A 11 minus− B 33...

  • KEY TERMS MATCHING Match the definition with the correct term from the following word list. A....

    KEY TERMS MATCHING Match the definition with the correct term from the following word list. A. administrative code set B. billing provider C. carrier block D. claim attachment E. claim control number F. claim filing indicator code G. claim frequency code (claim submission reason code) H. claim scrubber I. clean claims J. CMS-1500 claim K. condition code L. data elements M. destination payer N. 5010 version O. HIPAA X12 276/277 Health Care Claim Status Inquiry/Response P. individual relationship code Q....

  • PYTHON Hello can someone create the following functions? I'm not sure how to start on them....

    PYTHON Hello can someone create the following functions? I'm not sure how to start on them. makeDictionary Define a function named makeDictionary with two parameters. The first argument passed the function must be a list of strings to be used as keys, while the second is a list of the same length containing values (of some type). This function must return a dictionary consisting of the keys paired with the corresponding values. For example, makeDictionary(['apno','value'],['REP-12','450']) must return this dictionary: {'apno':...

  • Excersise 2.26 a sla D. Prepare Exercise 2-26 Required Relationship of accounts to financial statements Identify...

    Excersise 2.26 a sla D. Prepare Exercise 2-26 Required Relationship of accounts to financial statements Identify whether each of the following items would appear on the income statement (IS), statement of changes in stockholders' equity (SE), balance sheet (BS), or statement of cash flows (CF). Some items may appear on more than one statement, if so, identify all applicable statements. If an item would not appear on any financial statement, label it NA. a. Supplies b. Cash Flow from Financing...

  • nomenclature I. Nomenclature: For full credit use the letters provided!!!! 10 points CH, CH-C-CH.CH.CH A) 2-Butanone...

    nomenclature I. Nomenclature: For full credit use the letters provided!!!! 10 points CH, CH-C-CH.CH.CH A) 2-Butanone B) 4-Pentynonan-5-one C) 2-Naphthaldehyde D) 4- Propyloctan-2-one E) 2-Propyl-4-octanone F) Cyclohexane Carbaldehyde G) Cyclohexanecarbaldehyde H) 1-Cyclohexylmethanal D) 1-Butanone J4-Butyl-2-hexanone K) 1-Acetylcyclohexane L) 2-Methylbenzaldehyde M) Cyclobutanone N) 2-Methylacetophenone 0) Cyclobutanecarbaldehyde O) Diethyl Ketone P) 1.Naphthaldehyde Penta-1-one R) Cyclopentanecarbaldehyde S) Cyclopentane Carbaldehyde T 4-Pentanone U) 1-Formylcyclopentane W) 4-Butyl-3-nonanone X) 4-Pentyl-3-octanone Y) 3-Butyl-6-nonanone Z) 4-Acetophenone AA) 4-Methylbenzaldehyde BB) 6-Propyldecanal CC) 3-Hexanone DD) Dimethylketone EE) Cyclopentanone FF) Oscacyclopentane...

  • Python 2.7 Write a function cumsum() that takes a list l as argument and returns the...

    Python 2.7 Write a function cumsum() that takes a list l as argument and returns the cumulative sum (also known as the prefix sum) of l, which is a list, say cs of the same length as l such that each element cs[i] is equal to the sum of the first i + 1 elements of l, i.e., cs[i] == l[0] + l[1] + l[2] + ... + l[i] You should not modify the argument list l in any way....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT