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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -