Monday, 20 October 2014

Remove Lesser Values from List

I have a text file that contains:
xxx_123
xxx_001
xxx_345
YYY_123
ZZZ_789
ZZZ_123
I want to return a list with:
xxx_345
YYY_123
ZZZ_789
for item in list1:
    item = item.split("_")
    part1 = item[0]
    part2 = item[1]

    if part1 == part1:
        if part2>part2:
            print item
    print "Items do not match"
any thoughts?

Ans))  You need another loop within.
 for item in list1:
        item = item.split("_")
        part1 = item[0]
        part2 = item[1]

       for itemCheck in list1:
          itemCheck =itemCheck.split("_");
          part1Check= item[0]
          part2Check = item[1]
          if part1 == part1Check:
            if part2>part2Check:
             print item
            else:
             print itemCheck
        print "Items do not match"

No comments:

Post a Comment