Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 How to get the index of a character from a string
#1
Hi, i used this code it is getting the index value but i need it to get the index value as the expected output
s = 'Apples are totally awesome'
l = []
for idx, item in enumerate(s.lower()):
if 'a' in item:
l.append(idx)
if('l' in item) and ('a' in s[idx-1]):
l.append(idx)
print(l)

Actual output:
[0,7,14,15,20]

Expected output:
[0,7,14,15,16,20]
buran wrote Dec-03-2019, 12:51 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Quote
#2
can you explain the desired output in plain english
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  how can i handle "expected a character " type error , when I input no character vivekagrey 2 128 Jan-05-2020, 11:50 AM
Last Post: vivekagrey
  Unicode string index problem luoheng 6 200 Nov-23-2019, 03:04 PM
Last Post: luoheng
  python gives wrong string length and wrong character thienson30 2 215 Oct-15-2019, 08:54 PM
Last Post: Gribouillis
  IndexError: string index out of range ? Q_Y 5 1,092 Jul-05-2019, 07:18 PM
Last Post: noisefloor
  Find string and add character - newbi PyDK 1 263 May-15-2019, 01:22 PM
Last Post: ichabod801
  remove string character from url jacklee26 10 1,156 Mar-25-2019, 03:56 PM
Last Post: Larz60+
  Replace changing string including uppercase character with lowercase character silfer 11 959 Mar-25-2019, 12:54 PM
Last Post: silfer
  Changing a character in a string Livne_ye 4 471 Mar-13-2019, 12:39 PM
Last Post: Larz60+
  How Do I find Index of a character in string? ilcaa72 5 892 May-23-2018, 11:44 PM
Last Post: wavic
  testing if a character in a string is an intended one Skaperen 2 761 Feb-27-2018, 02:51 AM
Last Post: Skaperen

Forum Jump:


Users browsing this thread: 1 Guest(s)