[Tutor] WindowsSE/Python User Need Help With Dictionaries

Ignacio Vazquez-Abrams ignacio@openservices.net
Thu, 30 Aug 2001 10:56:24 -0400 (EDT)


On Thu, 30 Aug 2001, Ignacio Vazquez-Abrams wrote:

> The problem is that you're overwriting the dicitonary through each loop:
>
> ---
> def menu1():
>   v1=raw_input('...')
>   v2=raw_input('...')
>   c=raw_input('...')
>   l=[]
>   while c>0:
>     n=raw_input('...')
>     d={'a':v1, 'b':v2, 'c':n}
>     c=c-1
>     l.append(d)
>   return d
>
> print menu1()
> ---

Whoops! My bad.

---
def menu1():
  v1=raw_input('...')
  v2=raw_input('...')
  c=raw_input('...')
  d={'a':v1, 'b':v2, 'c':[]}
  while c>0:
    n=raw_input('...')
    c=c-1
    d['c'].append(n)
  return d

print menu1()
---

-- 
Ignacio Vazquez-Abrams  <ignacio@openservices.net>