python - How to remove brackets from output (i.e. [ ]) and other -



python - How to remove brackets from output (i.e. [ ]) and other -

i having problem getting right output out code(for school). st = input string ch = input character(this python search ch in st) code find both uppercase , lowercase of character set in ch, , shows position in output(in reverse order). so, typed code in

def whichpositionsrev (st, ch): if ch in st: inversefindchar = [index index,char in enumerate(list(st)) if char==ch ] homecoming "yes..." + str(inversefindchar[::-1]) else: homecoming "no"

i suppose 'yes...8 5 2 ' homecoming value(if typed in 'abxabxabx' st , 'x' ch), i'm maintain getting 'yes...[8, 5, 2]' output. want know part code causing set in brackets , commas in homecoming output?

because you're calling str() on array, getting string representation of array.

replace

str(inversefindchar[::-1])

with

" ".join(str(x) x in inversefindchar[::-1])

python enumerate

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -