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

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

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

android - How to create dynamically Fragment pager adapter -