[Tutor] sorting based on elements which are nested in a list

2011-04-03 Thread ranjan das
I have a list which I want to sort based on ('a','b','c') first and then based on (1,2,3) How do i do these using itemgetter() since the list is nested A=[('k3', ['b', 3]), ('k2', ['a', 1]), ('k1', ['a', 3]), ('k4', ['c', 2])] The solution I am looking for is A_sorted=[ ('k2', ['a', 1]), ('k1

[Tutor] Removing values from a dictionary if they are present in a list

2011-04-01 Thread ranjan das
I have the following information A={'g2': [4,5,3], 'g1': [1, 3]} B=[2,3,5] Now I want to remeove the elements in B if they are present (as values) in dictionary A. My expected solution is A= {'g2': [4], 'g1': [1] } I wrote the following piece of code which gives me thhe right code, but I am s

[Tutor] Grouping based on attributes of elements in a List

2011-03-29 Thread ranjan das
I have the following list List=[( 'G1', 'CFS', 'FCL', 'R1' ),('G3', 'LOOSEFREIGHT', 'MIXEDLCL', 'R9'), ('G4', 'CFS', 'FCL', 'R10' ), ('G2', 'LOOSEFREIGHT', 'LCL', 'R4' ), ('G1', 'CFS', 'FCL', 'R2' ), ('G2', 'LOOSEFREIGHT', 'LCL', 'R5') ] now I want to group this elements of List first by inde

[Tutor] Sorting a dictionary by a value when the values are tuples

2011-03-05 Thread ranjan das
This is a small example i created from operator import itemgetter temp={'4':(2,3), '2':(5,8)} print temp.items() new_temp=sorted(temp.items(), key=itemgetter(1) print new_temp I want to sort the dictionary by the value in the first element of the tuple ((2,3) and (5,8)) and then the second

Re: [Tutor] Error while using calendar module in Python 2.7

2011-03-04 Thread ranjan das
(year-month-day) =", today print "Most recent Monday =", monday On Sat, Mar 5, 2011 at 1:20 PM, ranjan das wrote: > Sorry David > > > > > > > Is there any change in the calendar module from Python 2.6 to 2.7. > > This example works fine in Python 2.6 b

Re: [Tutor] Error while using calendar module in Python 2.7

2011-03-04 Thread ranjan das
Sorry David The correctly indented code with the while loop is while friday.weekday() != calendar.MONDAY: MONDAY -= oneday oneweek = datetime.timedelta(days=7) nextweek = today + oneweek nextyear = today.replace(year=today.year+1) print "Today (year-month-day) =", today print "Most r

[Tutor] Error while using calendar module in Python 2.7

2011-03-04 Thread ranjan das
I ran the following code in python 2.6 and then in python 2.7 (using calendar module) to manipulate dates and times The following code works fine in Python 2.6 but throws up an error in Python 2.7. Can anyone please say why? CODE: import datetime import calendar while monday.weekday() != cal

[Tutor] Unintentionally manipulating a list

2011-02-25 Thread ranjan das
I am facing the following problem I have a list of the form INPUT= [ [ ['A1-N','A2-Y','A3-N' ],['B1-Y','B2-N','B3-N' ] ], [.] ] and I want an output of the form (selecting only those elements which have a Y associated with them) OUTPUT=[ ['A2-Y', 'B1-Y'],[] ] I wrote the followi

[Tutor] Clubbing simillar elements together in a list with repeating elements

2011-02-24 Thread ranjan das
I have a list a=[1,2,3,4,2,5,5,4,6,7,8] I want to club the repeating elements together and my output should be something like a_new=[ [1], [2,2], [3], [4,4] , [5,5,5],[6], [7], [8]] How do I do this? I tried the following but it is not giving me the desired result a=[1,2,3,2,3,4,5,4,5,5,6]

Re: [Tutor] Help-Embedding Python in C#

2010-09-22 Thread ranjan das
: Write the code completely in python and then from it create a windows web based application. Any help is appreciated Regards, Ranjan On Wed, Sep 22, 2010 at 6:38 PM, Wayne Werner wrote: > On Wed, Sep 22, 2010 at 7:55 AM, ranjan das wrote: > >> >> Please Advise: >> >>

[Tutor] Help-Embedding Python in C#

2010-09-22 Thread ranjan das
Please Advise: I need to run/execute python module in C#. I am using python 2.6 and visual studio 10 Ranjan ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

[Tutor] Extracting lines in a file

2010-04-05 Thread ranjan das
Hi, I am new to python, and specially to file handling. I need to write a program which reads a unique string in a file and corresponding to the unique string, extracts/reads the n-th line (from the line in which the unique string occurs). I say 'n-th line' as I seek a generalized way of doing

Re: [Tutor] How to print the next line in python

2009-09-12 Thread ranjan das
Thanks a lot Andre...it is working On Sat, Sep 12, 2009 at 2:17 PM, Andre Engels wrote: > On Sat, Sep 12, 2009 at 10:35 AM, ranjan das > wrote: > > Hi, > > > > I am new to python and i wrote this piece of code which is ofcourse not > > serving my purpose: >

[Tutor] How to print the next line in python

2009-09-12 Thread ranjan das
Hi, I am new to python and i wrote this piece of code which is ofcourse not serving my purpose: Aim of the code: To read a file and look for lines which contain the string 'CL'. When found, print the entry of the next line (positioned directly below the string 'CL') continue to do this till