Jun-11-2020, 09:28 PM
(This post was last modified: Jun-11-2020, 10:07 PM by knackwurstbagel.)
In the code I provided, replacing extend with append, and printing results seemed to do the trick. I forgot how extend and append works, that was my mistake. In your latest code the whole 'zzz' thing is confusing, I would just use a single strip to get rid of the trailing periods and exclamations. I was reading your transcript and I would like to suggest a few changes.
Why? for 30 In the docs "The chars argument is not a suffix; rather, all combinations of its values are striped"
This can be confusing, I devised a few experiments:
But in either case
Python is dynamically typed and these are just hints to the user of what types the arguments are and in the case of -> list, that it returns a list. It is just a kind way of telling the programmer who is going to use your function that text is a str type and that the function returns a list. It can be safely removed.
Quote:24 declare variable line as line with spaces trimmed
30 if last word ends with any combination of ! and . strip it
Why? for 30 In the docs "The chars argument is not a suffix; rather, all combinations of its values are striped"
This can be confusing, I devised a few experiments:
words = ['both!.', 'single.', 'reversed.!', 'exclamation!'] for word in words: print(word.rstrip('!.')) # As comprehension print([word.rstrip('!.') for word in words])Can you guess the output before running this? In either case, if your 'zzz' method works that's great (I've not run that code) but it seems your failing the second test and, I would say that instead of
Quote:re-write my code so that it automatically returns ['word', 'list', 'list'] based on the secondary text stringI would try to debug your code with a debugger either one provided in vscode, PyCharm..., or the one python comes with pdb, I personally use pdb++. Its worth learning and saves a lot of print statements, as usually when your printing the value of variables, its because you suspect it does not contain what you think it does. In pdb you can set a breakpoint and then do
display <variable_name>
to track the value of that variable as it changes.But in either case
Quote:At line 19, the function parameter is: text: str = text. How does this work? The variable text makes sense, but how and why does the string class method equal text? Also: What does -> list do?is python typing
Python is dynamically typed and these are just hints to the user of what types the arguments are and in the case of -> list, that it returns a list. It is just a kind way of telling the programmer who is going to use your function that text is a str type and that the function returns a list. It can be safely removed.
Apologetic Canadian, Sorry about that eh?