[Tutor] Unique Items in Lists

Srinivas Iyyer srini_iyyer_bio at yahoo.com
Wed Jan 26 19:44:01 CET 2005

  I am a new member to this group and relatively to

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


col1    col2    col3   col4
A       Apple     5    Chennai
B       Baby     11    Delhi
I       Baby*     1    Delhi
M       Dasheri+  5    Mumbai
K       Apple     12   Copenhagen

* -> Baby => Infant  + -> Dasheri => Mango

for ele in table:
     col2 = ele.split('\t')[1]

col2_set = sets.Set(col2)

col2_set -> (Apple,Baby Dasheri)
Apple     A,K     5,12    Chennai, Copenhagen
Baby      B,I     1,11    Delhi
Dasheri   M       5       Mumbai.

for ele in col1_set:
     nam = ele.strip()
     for k in list:
         m = re.search(nam,k)
         cols = k.split('\t')
         a = cols[0]
         n = cols[2]
         c = cols[3]
         print nam+'\t'+a+'\t'+n+'\t'+c

A dictionary option does not work beca

This isnt working properly. 
please help me any one 

question 2:

A list with 100 unique items, repeated several times. 

Apples  - repeated 1000 times in list
Vegie   - repeated 300 times in list

how can I get a uniq elements that repeated several

for item in range(len(list)):
     for k in range(len(list)):
        if item == k:
            if list[item] != k[list]:
                      print item

This isnt working either.  logic appears correct.
looking forward for help pleas.

thank you


Do you Yahoo!? 
The all-new My Yahoo! - What will yours do?

More information about the Tutor mailing list