django - Display Loop from Database correctly Python -
i display word 'conflict' if value more 1 in list. code
list = ['aa','bb','cc','aa'] conf = [s s in list] in list: if len(a in conf) > 1: print a, "-conflict" else: print
i think syntax wrong in if len(a in conf)> 1: please me.
i expecting result:
aa - conflict bb cc aa - conflict
you can use count function.
if conf.count(a) > 1: print a, "-conflict"
the above method similar have tried. inefficient when list large. so, use collections.counter.
from collections import counter occurences = counter(conf) in list: if occurences[a] > 1: print a, "- conflict" else: print
Comments
Post a Comment