Python Forum
How to get the index of a character from a string
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to get the index of a character from a string
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:
if('l' in item) and ('a' in s[idx-1]):

Actual output:

Expected output:
can you explain the desired output in plain english
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs


Possibly Related Threads…
Thread Author Replies Views Last Post
  SyntaxError: unexpected character after line continuation character siteshkumar 2 349 Jul-13-2020, 07:05 PM
Last Post: snippsat
  String index out of bounds ( Python : Dict ) kommu 2 417 Jun-25-2020, 08:52 PM
Last Post: menator01
  Remove from end of string up to and including some character lbtdne 2 473 May-17-2020, 09:24 AM
Last Post: menator01
  String index out of range - help please DudleyDiccle 7 646 Mar-27-2020, 12:10 AM
Last Post: DudleyDiccle
  how can i handle "expected a character " type error , when I input no character vivekagrey 2 586 Jan-05-2020, 11:50 AM
Last Post: vivekagrey
  Unicode string index problem luoheng 6 652 Nov-23-2019, 03:04 PM
Last Post: luoheng
  python gives wrong string length and wrong character thienson30 2 667 Oct-15-2019, 08:54 PM
Last Post: Gribouillis
  IndexError: string index out of range ? Q_Y 5 1,853 Jul-05-2019, 07:18 PM
Last Post: noisefloor
  Find string and add character - newbi PyDK 1 537 May-15-2019, 01:22 PM
Last Post: ichabod801
  remove string character from url jacklee26 10 1,920 Mar-25-2019, 03:56 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020