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
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", "
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
> 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.
___
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
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
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,
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
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
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
10 matches
Mail list logo