Array delete
azrael
jura.grozni at gmail.com
Wed Feb 7 20:13:19 EST 2007
if you are new to python then this will be easier to understand. if
you change this a liitle bit (depending on syntax) it should work in
any language.
just copy and paste to a .py file
def main():
list, temp = [1, 1, 2, 4, 8, 8, 8, 8, 8, 8, 10], []
for i in range(len(list)):
if Check(list[i], temp) == 1:
temp.append(list[i])
print temp # print the new list where duplicates are removed
def Check(listItem,temp):
for i in range(len(temp)):
if listItem == temp[i]:
return 0
return 1
if __name__=="__main__":
main()
On Feb 7, 10:35 pm, "Jerry Hill" <malaclyp... at gmail.com> wrote:
> On 1/28/07, Scripter47 <nos... at riddergarn.dk> wrote:
>
> > Can someone plz make a function for that takes a array, and then search
> > in it for duplicates, if it finds 2 or more items thats the same string
> > then delete all except 1.
>
> >>> myList = [1, 1, 2, 4, 8, 8, 8, 8, 8, 8, 10]
> >>> myList = list(set(myList))
> >>> print myList
> [8, 1, 2, 4, 10]
>
> Maintaining sort order is left as an exercise for the reader.
>
> --
> Jerry
More information about the Python-list
mailing list