Oct-05-2018, 02:20 AM
I’m trying to create a list for every first letter in the given string.
Here is my script:
My actual output:
My loop creates a new list for every item. That’s not what I want. I figure I need to append every item each time when
For my future reference, this forum thread refers to Task #3 in Jose Portilla’s so called 04-Field-Readiness-Exam-2 in his “Narrative Journey” Udemy Python course material (on GitHub: Pierian-Data/Python-Narrative-Journey).
Thanks for your attention.
Here is my script:
mystring = "Secret agents are super good at staying hidden." words = mystring.split() for char in words: first_char_list = char[0] print(list(first_char_list))My expected output:
Quote:['S', 'a', 'a', 's', 'g', 'a', 's', 'h']
My actual output:
Quote:['S']
['a']
['a']
['s']
['g']
['a']
['s']
['h']
My loop creates a new list for every item. That’s not what I want. I figure I need to append every item each time when
char
completes its iteration. I’ve kind of done that already, but evidently I’m not doing it properly. I am not sure what I am doing wrong.For my future reference, this forum thread refers to Task #3 in Jose Portilla’s so called 04-Field-Readiness-Exam-2 in his “Narrative Journey” Udemy Python course material (on GitHub: Pierian-Data/Python-Narrative-Journey).
Thanks for your attention.