python - IDLE settings change, comment key change -


this not programming question question idle. possible change comment block key '#' else?

here part not going work:

    array = []     y = array.append(str(words2)) <-- part of program     hash = y.count(#) <-- part won't work     print("there are", hash, "#'s") 

no, isn't specific idle part of language.

edit: i'm pretty sure want use

y.count('#') # note quotes

remember 1 of strengths of python portability. writing program work custom version of interpreter removing strengths of language.

as rule of thumb anytime find thinking solution rewrite part of language might heading in wrong direction.

you need call count on string not list:

array = []     y = array.append(str(words2)) <-- part of program     hash = y[0].count('#')  # note quotes , calling count on element of list not whole list      print("there are", hash, "#'s") 

with output:

>>> l = [] >>> l.append('#$%^&###%$^^') >>> l ['#$%^&###%$^^'] >>> l.count('#') 0 >>> l[0].count('#') 4 

count looking exact match , '#$%^&###%$^^' != '#'. can use on list so:

>>> l =[] >>> l.append('#') >>> l.append('?') >>> l.append('#') >>> l.append('<') >>> l.count('#') 2 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -