[Tutor] help

2009-03-13 Thread Sanhita Mallick

help


--- On Sat, 3/14/09, tutor-requ...@python.org tutor-requ...@python.org wrote:

 From: tutor-requ...@python.org tutor-requ...@python.org
 Subject: Tutor Digest, Vol 61, Issue 50
 To: tutor@python.org
 Date: Saturday, March 14, 2009, 5:18 AM
 Send Tutor mailing list submissions to
   tutor@python.org
 
 To subscribe or unsubscribe via the World Wide Web, visit
   http://mail.python.org/mailman/listinfo/tutor
 or, via email, send a message with subject or body
 'help' to
   tutor-requ...@python.org
 
 You can reach the person managing the list at
   tutor-ow...@python.org
 
 When replying, please edit your Subject line so it is more
 specific
 than Re: Contents of Tutor digest...
 
 
 Today's Topics:
 
1. update list of dictionaries based on key (ski)
2. Re: update list of dictionaries based on key (greg
 whittier)
3. Re: update list of dictionaries based on key (ski)
4. best gui for the job? (W W)
5. Re: best gui for the job? (Lie Ryan)
 
 
 --
 
 Message: 1
 Date: Fri, 13 Mar 2009 16:09:58 +0100
 From: ski nor...@khine.net
 Subject: [Tutor] update list of dictionaries based on key
 To: python tutor tutor@python.org
 Message-ID: 49ba7746.6090...@khine.net
 Content-Type: text/plain; charset=ISO-8859-1; format=flowed
 
 Hello,
 Here is what I have so far:
 
   mylist = [{'index': 0,
 'title': 'Association of British Travel 
 Agents', 'selected': False, 'edit_row':
 '?edit_affiliation=0', 
 'affiliation': 'ABTA',
 'affiliation_no': u'G3903'},
 {'index': 1, 
 'title': 'Appointed Agents of IATA',
 'selected': False, 'edit_row': 
 '?edit_affiliation=1', 'affiliation':
 'IATA', 'affiliation_no': 
 u'none'}, {'index': 0, 'title':
 'Association of Airline Cons.', 
 'selected': False, 'edit_row':
 '?edit_affiliation=0', 'affiliation': 
 'AAC', 'affiliation_no': u'sss'},
 {'index': 1, 'title': 'Association of 
 British Travel Agents', 'selected': False,
 'edit_row': 
 '?edit_affiliation=1', 'affiliation':
 'ABTA', 'affiliation_no': u'zser'}]
 
   key = 'affiliation_no'
 
   my_dup_keys = []
   merged_list = []
 
   mykeys = [item['affiliation'] for
 item in mylist]
 
   for x in mykeys:
   if mykeys.count(x) = 2:
   my_dup_keys.append(x)
 
   for item in mylist:
   if item['affiliation'] in set(my_dup_keys):
   merged_list.append(item)
 
 
   values = [d[key] for d in merged_list if
 d.has_key(key)]
   for dict in merged_list:
   dict[key] = values
   mylist.append(dict)
 
   print mylist
 [{'index': 0, 'title': 'Association of
 British Travel Agents', 
 'selected': False, 'edit_row':
 '?edit_affiliation=0', 'affiliation': 
 'ABTA', 'affiliation_no':
 [u'G3903', u'zser']}, {'index': 1,
 'title': 
 'Appointed Agents of IATA', 'selected':
 False, 'edit_row': 
 '?edit_affiliation=1', 'affiliation':
 'IATA', 'affiliation_no': 
 u'none'}, {'index': 0, 'title':
 'Association of Airline Cons.', 
 'selected': False, 'edit_row':
 '?edit_affiliation=0', 'affiliation': 
 'AAC', 'affiliation_no': u'sss'},
 {'index': 1, 'title': 'Association of 
 British Travel Agents', 'selected': False,
 'edit_row': 
 '?edit_affiliation=1', 'affiliation':
 'ABTA', 'affiliation_no': 
 [u'G3903', u'zser']}, {'index': 0,
 'title': 'Association of British 
 Travel Agents', 'selected': False,
 'edit_row': '?edit_affiliation=0', 
 'affiliation': 'ABTA',
 'affiliation_no': [u'G3903',
 u'zser']}, {'index': 
 1, 'title': 'Association of British Travel
 Agents', 'selected': False, 
 'edit_row': '?edit_affiliation=1',
 'affiliation': 'ABTA', 
 'affiliation_no': [u'G3903',
 u'zser']}]
 
 
 This sort of works but I want to return a list that updates
 'mylist' not 
 append to it, so I will get:
 
 [{'index': 0, 'title': 'Association of
 British Travel Agents', 
 'selected': False, 'edit_row':
 '?edit_affiliation=0', 'affiliation': 
 'ABTA', 'affiliation_no':
 [u'G3903', u'zser']}, {'index': 1,
 'title': 
 'Appointed Agents of IATA', 'selected':
 False, 'edit_row': 
 '?edit_affiliation=1', 'affiliation':
 'IATA', 'affiliation_no': 
 u'none'}, {'index': 0, 'title':
 'Association of Airline Cons.', 
 'selected': False, 'edit_row':
 '?edit_affiliation=0', 'affiliation': 
 'AAC', 'affiliation_no': u'sss'}]
   
 
 Thanks
 
 Norman
 
 
 
 --
 
 Message: 2
 Date: Fri, 13 Mar 2009 11:43:19 -0400
 From: greg whittier g...@thewhittiers.com
 Subject: Re: [Tutor] update list of dictionaries based on
 key
 To: python tutor tutor@python.org
 Message-ID:
   a250eacf0903130843o6aed2c3bk1893a20feed0c...@mail.gmail.com
 Content-Type: text/plain; charset=ISO-8859-1
 
 On Fri, Mar 13, 2009 at 11:09 AM, ski
 nor...@khine.net wrote:
  Hello,
  Here is what I have so far:
 
  mylist = [{'index': 0,
 'title': 'Association of British Travel
 Agents',
  'selected': False,
 'edit_row': '?edit_affiliation=0',
 'affiliation': 'ABTA',
  'affiliation_no':
 u'G3903'}, {'index': 1, 'title':
 'Appointed 

Re: [Tutor] Help with Recurring Function

2008-04-27 Thread Sanhita Mallick
Hi Alan.

Thanks a lot. It worked 

 --
 
 Message: 2
 Date: Sat, 26 Apr 2008 13:46:39 +0100
 From: Alan Gauld [EMAIL PROTECTED]
 Subject: Re: [Tutor] Help with Recurring Function
 To: tutor@python.org
 Message-ID: [EMAIL PROTECTED]
 Content-Type: text/plain; format=flowed;
 charset=iso-8859-1;
   reply-type=original
 
 
 Sanhita Mallick [EMAIL PROTECTED] wrote 
 
 
  being calculated correctly as checked by the
 print
  statement. But when we do 
  
  norm_ted = (2 * ted) / mag
 
 It might be an integer division issue.
 
 Try 
 
 norm_ted = (2*ted) / float(mag)
 
 Just a thought...
 
 
 -- 
 Alan Gauld
 Author of the Learn to Program web site
 http://www.freenetpages.co.uk/hp/alan.gauld
 
 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help with Recurring Function

2008-04-26 Thread Sanhita Mallick
Hi Kent.

sum_norm_ted is sum over each i, and all j. That is
why it is initialize to zero at the beginning of each
i loop.

The inner loop IS running - which I checked by all the
print statements. The value of ted and mag ARE
being calculated correctly as checked by the print
statement. But when we do 

norm_ted = (2 * ted) / mag

becomes zero, and subsequently sum_norm_ted becomes
zero. 


--- Kent Johnson [EMAIL PROTECTED] wrote:

 Sanhita Mallick wrote:
 
  I am struggling with a simple recurring function
 
 What is a recurring function? Do you mean looping?
  
  Here is the script. T(i) are trees (as in graphs).
  The program operates great, until the step where
  norm_ted is calculated. Mysteriously norm_ted
 becomes
  0, even though mag value is calculated
 correctly.
  Also, strangely, sum_norm_ted also becomes zero. 
  
  What am I missing?
 
 Do you mean for sum_norm_ted to be the sum over all
 i and j? If so, you 
 should initialize it before the start of the outer
 loop.
 
 I don't know why you are getting 0 at the end of the
 loop. It is as if 
 sum_norm_ted and norm_ted are initialized but the
 inner loop doesn't 
 run. Is this the exact code that you have trouble
 with?
 
 Kent
  
  Thanks.
  -Sanhita
  
  ~~~
  T = [F1, F2, F3]
  k = len(T)
  mean_ted = {}
  for i in range(k):
  sum_norm_ted = 0.0
  mag = 0.0
  norm_ted = 0.0
  for j in range(k):
  if (i != j):
  ted= alg.ted(T[i], T[j])
  print 'TED ' + str(i) + str(j) + ' is
 ' +
  str(ted)
  mag = 2 * (T[i].n + T[j].n) - 1
  print 'MAG ' + str(i) + str(j) + ' is
 ' +
  str (mag) + ' and ' + str ( 2 * ted )
  norm_ted = (2 * ted) / mag 
  print 'norm_ted ' + str(i) + str(j) +
 ' is
  ' + str (norm_ted)
  sum_norm_ted = sum_norm_ted + norm_ted
  print 'sum_norm_ted ' + str(i) +
 str(j) +
  ' is ' + str (sum_norm_ted)
  ___
  Tutor maillist  -  Tutor@python.org
  http://mail.python.org/mailman/listinfo/tutor
  
 
 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Help with Recurring Function

2008-04-25 Thread Sanhita Mallick
Hi.

I am struggling with a simple recurring function, but
can't understand why this is happening. Please help.

Here is the script. T(i) are trees (as in graphs).
The program operates great, until the step where
norm_ted is calculated. Mysteriously norm_ted becomes
0, even though mag value is calculated correctly.
Also, strangely, sum_norm_ted also becomes zero. 

What am I missing?

Thanks.
-Sanhita

~~~
T = [F1, F2, F3]
k = len(T)
mean_ted = {}
for i in range(k):
sum_norm_ted = 0.0
mag = 0.0
norm_ted = 0.0
for j in range(k):
if (i != j):
ted= alg.ted(T[i], T[j])
print 'TED ' + str(i) + str(j) + ' is ' +
str(ted)
mag = 2 * (T[i].n + T[j].n) - 1
print 'MAG ' + str(i) + str(j) + ' is ' +
str (mag) + ' and ' + str ( 2 * ted )
norm_ted = (2 * ted) / mag 
print 'norm_ted ' + str(i) + str(j) + ' is
' + str (norm_ted)
sum_norm_ted = sum_norm_ted + norm_ted
print 'sum_norm_ted ' + str(i) + str(j) +
' is ' + str (sum_norm_ted)
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Arguments ina separate file

2008-04-21 Thread Sanhita Mallick
Hi.

I have a big list of arguments, which I would like to
keep in a  separate file. How do I pass arguments that
are in a  separate file?

Thanks.
San
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Graphs in Python

2008-04-10 Thread Sanhita Mallick
Hi.

I am a newbie to Python. I am trying to implement a
Python code for graph manipulation. My graphs are
about 200-500 nodes big. Excepting for the short basic
graph implementation info on Python.org, where can I
find more in depth info about how to express graphs in
python, and how to use them in a  code?

Also, does anyone know of a easy way of creating the
dictionary for python for a 500-node graph, without
typing each and every node? I found some application
that recognize dot file Graphviz - but I am looking
for a program that can let me draw a graph and then
generate the lists automatically from the drawing.

Thanks.
-SM
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor