Generating multiple lists from one list

2006-07-05 Thread Girish Sahani
hello ppl, Consider a list like ['a.1','b.3','b.4','c.2']. Here 'a','b','c' are objects and 1,3,4,2 are their instance ids and they are unique e.g. a.1 and b.1 cannot exist together. From this list i want to generate multiple lists such that each list must have one and only one instance of every

Generating multiple lists from one list

2006-07-05 Thread Girish Sahani
hello ppl, Consider a list like ['a.1','b.3','b.4','c.2']. Here 'a','b','c' are objects and 1,3,4,2 are their instance ids and they are unique e.g. a.1 and b.1 cannot exist together. From this list i want to generate multiple lists such that each list must have one and only one instance of every

Re: How to measure execution time of a program

2006-06-28 Thread Girish Sahani
Sorry for spamming again, but please also enlighten me with some way to time a function i.e. to find out how much time each function takes for execution in a big program. > Hi all, > > Can anyone tell me the simplest way to do it (some code snippet that > could be included in the program's main f

How to measure execution time of a program

2006-06-28 Thread Girish Sahani
Hi all, Can anyone tell me the simplest way to do it (some code snippet that could be included in the program's main function) ?? Thanks, girish -- http://mail.python.org/mailman/listinfo/python-list

Function to prune dictionary keys not working

2006-06-27 Thread Girish Sahani
hi ppl, Here is a simple function to remove those keys of a dictionary whose values are less than some specified value. But it isnt working. Please help. def prune(d,cp): l = [] for rule,value in d.iteritems(): #print value if value >= cp: l.append(rule) re

Re: How to generate all permutations of a string?

2006-06-22 Thread Girish Sahani
>> thanks lawrence...however this func doesnt return the permuted strings, >> so >> i added some code as follows to generate a list of all the permutations: >> >> def permute(seq): >> l = [] >> if len(seq) == 0: >> yield [] >> else: >> for i in range(0,len(seq)): >>

Re: How to generate all permutations of a string?

2006-06-22 Thread Girish Sahani
> In article <[EMAIL PROTECTED]>, > "Girish Sahani" <[EMAIL PROTECTED]> wrote: > >> I want to generate all permutations of a string. > > def permute(Seq) : > """generator which yields successive permutations of the eleme

How to generate all permutations of a string?

2006-06-22 Thread Girish Sahani
Hi guys, I want to generate all permutations of a string. I've managed to generate all cyclic permutations. Please help :) def permute(string): l= [] l.append(string) string1 = '' for i in range(0,len(string)-1,1): string1 = string[1:len(string)] + string[:1] l.ap

How to truncate/round-off decimal numbers?

2006-06-20 Thread Girish Sahani
Hi, I want to truncate every number to 2 digits after the decimal point. I tried the following but it doesnt work. >>> a = 2 >>> b = 3 >>> round(a*1.0 / b,2) 0.67004 Inspite of specifying 2 in 2nd attribute of round, it outputs all the digits after decimal. -- http://mail.python.org

Re: Getting "TypeError:list indices must be integers"

2006-06-13 Thread Girish Sahani
> On 13/06/2006 4:11 PM, Girish Sahani wrote: > [snip] >>instance = ti2(k) >>tiNew = ti1.append(instance) > > ti2 is quacking "function" but ti1 is quacking "list". > > Possibilities: > (1) You meant to type ti2[k] ... and this s

Getting "TypeError:list indices must be integers": apology

2006-06-13 Thread Girish Sahani
Hi ppl, I'm really sorry for the previous post. I write mails very quickly and end up making errors in it. This time i ended up giving a code portion from an old copy of my program. Here's the code portion that is giving a TypeError:list indices must be integers for index1 in indexList1: for ind

Getting "TypeError:list indices must be integers"

2006-06-12 Thread Girish Sahani
Hi, Please check out the following loop,here indexList1 and indexList2 are a list of numbers. for index1 in indexList1: for index2 in indexList2: if ti1[index1] == ti2[index2] and not index1 != indexList1.pop(): index1+=1 index2+=1 continue elif index1 == indexList1.

Re: Function to remove elements from a list working, but Python Hangs :((

2006-06-12 Thread Girish Sahani
> I guess it's already the case with lst = [ e for e in lst if e in pairs ] > > > In [1]: lst = (1,2,3,4) > > In [2]: pairs=(5,) > > In [3]: lst=[e for e in lst if e in pairs] > > In [4]: lst > Out[4]: [] Yes its working. I realized that i was giving an input which didnt satisfy the condition. Now

Re: Function to remove elements from a list working, but python hangs :((

2006-06-12 Thread Girish Sahani
big a data, this shouldnt happen Should it?? > Girish Sahani wrote: >> Hi, >> I am trying to convert a list of pairs (l4) to list l5 by removing >> those >> pairs from l4 which are not present in a third list called pairList. > > > > >> The fo

Re: Function to remove elements from a list not working (corrected)

2006-06-12 Thread Girish Sahani
Thank you Markthis works too... Btw going slightly off-topic, when i try to run a code like below with around 50 elements (pairs) in l4,python just hangs. Any ideas why this is happening...the data is not that large :(( > > Girish Sahani wrote: >> Hi, >> I am trying to modi

Re: Function to remove elements from a list not working (corrected)

2006-06-12 Thread Girish Sahani
= []. How can i do that? > Le Lundi 12 Juin 2006 10:25, Girish Sahani a écrit : >> Hi, >> I am trying to modify a list of pairs (l4) by removing those >> pairs which are not present in a third list called pairList. >> The following is a simplified part of the routine i hav

Function to remove elements from a list not working (corrected)

2006-06-12 Thread Girish Sahani
Hi, I am trying to modify a list of pairs (l4) by removing those pairs which are not present in a third list called pairList. The following is a simplified part of the routine i have written. However it does not give the correct output. Please help! Its possible i have made a trivial mistke sinc

Function to remove elements from a list not working

2006-06-12 Thread Girish Sahani
Hi, I am trying to convert a list of pairs (l4) to list l5 by removing those pairs from l4 which are not present in a third list called pairList. The following is a simplified part of the routine i have written. However it does not give the correct output. Please help! Its possible i have made a

Re: Error in Chain of Function calls (Code Attached)

2006-06-09 Thread Girish Sahani
Thanks for the help borisi'll try using sets instead of lists But i dont understand the point below...full traceback means what :-? > Girish Sahani wrote: > >>>> However i am getting an error at the line marked with ***. > >>> Which error ? How do you ho

Re: Error in Chain of Function calls (Code Attached)

2006-06-09 Thread Girish Sahani
> Girish Sahani wrote: >> Hi, >> >> There is a code in my main function which is something like: >> >> while prunedFinal != []: >> prunedNew = genColocations(prunedK) *** >> tableInstancesNew = &

Re: Error in Chain of Function calls

2006-06-09 Thread Girish Sahani
> Girish Sahani wrote: > >> However i am getting an error at the line marked with ***. > > what error ? ...line 266, in colocationMiner prunedNew = genColocations(prunedK) genColocations is a function defined before which returns prunedNew. > >> Also,i am getting a V

Error in Chain of Function calls

2006-06-09 Thread Girish Sahani
Hi, There is a code in my main function which is something like: while prunedFinal != []: prunedNew = genColocations(prunedK) *** tableInstancesNew = genTableInstances(prunedNew,tableInstancesK) tiCountDict = tiCount(tableInstancesNew) tiDic

Re: How to generate k+1 length strings from a list of k lengthstrings?

2006-06-08 Thread Girish Sahani
Yes it is the former of course.Common elements could be in any order in both strings. Thanks Marc :)...though we need to add an if for checking the length of the string (k+1). > > Jon Clements wrote: >> Are you asking the question, "Which pairs of strings have one character >> different in each?",

How to generate k+1 length strings from a list of k length strings?

2006-06-07 Thread Girish Sahani
I have a list of strings all of length k. For every pair of k length strings which have k-1 characters in common, i want to generate a k+1 length string(the k-1 common characters + 2 not common characters). e.g i want to join 'abcd' with bcde' to get 'abcde' but i dont want to join 'abcd' with 'c

Re: Reading from a file and converting it into a list of lines

2006-06-06 Thread Girish Sahani
> On 6/06/2006 4:15 PM, Girish Sahani wrote: >> Really sorry for that indentation thing :) >> I tried out the code you have given, and also the one sreeram had >> written. >> In all of these,i get the same error of this type: >> Error i get in Sreeram

Re: Reading from a file and converting it into a list of lines

2006-06-05 Thread Girish Sahani
Really sorry for that indentation thing :) I tried out the code you have given, and also the one sreeram had written. In all of these,i get the same error of this type: Error i get in Sreeram's code is: n1,_,n2,_ = line.split(',') ValueError: need more than 1 value to unpack And error i get in you

Re: the most efficient method of adding elements to the list

2006-06-05 Thread Girish Sahani
> Hi, > > Would it be .append()? Does it reallocate te list with each apend? Yes it does. If order of the new element being added doesnt matter you can use append. If it does, you can use insert(). > > l=[] > for i in xrange(n): >l.append(i) > > > Thx, A. > -- > http://mail.python.org/mailm

Reading from a file and converting it into a list of lines: code not working

2006-06-05 Thread Girish Sahani
I have a text file in the following format: 1,'a',2,'b' 3,'a',5,'c' 3,'a',6,'c' 3,'a',7,'b' 8,'a',7,'b' . . . Now i need to generate 2 things by reading the file: 1) A dictionary with the numbers as keys and the letters as values. e.g the above would give me a dictionary like {1:'a', 2:'b', 3:'a',

How to generate all k-1 level substrings of a string?

2006-06-05 Thread Girish Sahani
I want to generate all substrings of size k-1 from a string of size k. e.g 'abcd' should give me ['abc','abd','bcd','acd'] Order of these strings in the list doesnt matter. Also order doesnt matter inside the string e.g 'abc' or 'bca' or 'bac' is the same. I wrote the following code but it doesnt g

How to search for substrings of a string in a list?

2006-06-05 Thread Girish Sahani
Given a length k string,i want to search for 2 substrings (overlap possible) in a list consisting of length k-1 strings. These 2 substrings when 'united' give the original string. e.g given 'abc' i want to search in the list of 2-length strings ['ab',ac','cd','bc','bd'] to extract either 1) 'ab an

Concatenating dictionary values and keys, and further operations

2006-06-05 Thread Girish Sahani
I wrote the following code to concatenate every 2 keys of a dictionary and their corresponding values. e.g if i have tiDict1 = tiDict1 = {'a':[1,2],'b':[3,4,5]} i should get tiDict2={'ab':[1,2][3,4,5]} and similarly for dicts with larger no. of features. Now i want to check each pair to see if they