Re: [Tutor] Unique Items in Lists

2005-01-27 Thread Chad Crabtree
Try a simple bubble sort. This will not have great performance on big files at a worst case scenario it will take n-1 loops to sort. This is not very general and would require a substantially different implementation. def bublesort(l1,l2,l3): modified=True while modified: modif

Re: [Tutor] Unique Items in Lists

2005-01-27 Thread Bill Mill
Srinivas, You can't sort a string, since it's immutable. You can, however, sort a list. To sort your table by the third element, you can do something like this: >>> table = (("apple", "fruit", "denmark"), ... ("mummy", "antique", "egypt"), ... ("taj", "wonder", "india"), ... ("f-16", "fighter", "

Re: [Tutor] Unique Items in Lists

2005-01-27 Thread Srinivas Iyyer
Dear Danny, thank you for ur help. But a basic question ? In a table, more specifically a matrix 3X3, AppleFruitDenmark F-16 Fighter USA Taj Wonder India MummyAntique Egypt IF I have to sort on country, it should be AppleFruitDenmark MummyAntique Egypt Taj

Re: [Tutor] Unique Items in Lists

2005-01-27 Thread Alan Gauld
> for i in range(len(a)): > for k in range(len(a)): for k in range(i,len(a)): is faster, and if you calculate len before starting the loops that will speed it up too. (You calculate len for each iteration of each loop!) > if i != k: > if a[i] == a[k]: > print a[i] > break HTH Alan G. ___

Re: [Tutor] Unique Items in Lists

2005-01-26 Thread Brian van den Broek
Srinivas Iyyer said unto the world upon 2005-01-27 01:17: Dear Jacob, thank you for your suggestion. however, i think my question was not clear. what i meant to ask in my previous question was, how to know which elements repeated and how many times they were repeated. while my question was flying

Re: [Tutor] Unique Items in Lists

2005-01-26 Thread Chad Crabtree
Ok. I think I understand and I happen to be up at 1:30 my time so here is the solution as I understand the problem. This is a very common problem and has a fairly easy solution. You can then take adict.keys() which returns a list of unique elements. Good Luck import random l=[random.randra

Re: [Tutor] Unique Items in Lists

2005-01-26 Thread Srinivas Iyyer
Dear Jacob, thank you for your suggestion. however, i think my question was not clear. what i meant to ask in my previous question was, how to know which elements repeated and how many times they were repeated. while my question was flying, i did a small test: took a list: >>> a [1, 1, 2, 3, 4,

Re: [Tutor] Unique Items in Lists

2005-01-26 Thread Jacob S.
col2_set = sets.Set(col2) how can I get a uniq elements that repeated several times: for item in range(len(list)): for k in range(len(list)): if item == k: if list[item] != k[list]: print item First off, this would never work. You are iterating over the s

Re: [Tutor] Unique Items in Lists

2005-01-26 Thread Danny Yoo
On Wed, 26 Jan 2005, Srinivas Iyyer wrote: > I have a list with 4 columns and column1 elements are unique. I wanted > to extract unique elements in column3 and and place the other elements > of the column along with unique elements in column 4 as a tab delim > text. > > Table: > > col1col2

[Tutor] Unique Items in Lists

2005-01-26 Thread Srinivas Iyyer
Hi, I am a new member to this group and relatively to python. I have a list with 4 columns and column1 elements are unique. I wanted to extract unique elements in column3 and and place the other elements of the column along with unique elements in column 4 as a tab delim text. Table: col1