Sep-15-2019, 07:02 AM
(This post was last modified: Sep-15-2019, 07:02 AM by YoungGrassHopper.)
(Sep-14-2019, 10:41 AM)metulburr Wrote: its better to hard code and remove input() when posting on the forums such as
string = 'The quick brown fox jumps over the lazy dog. ' characters = 'aeiou' stripped_str = string.strip(characters) print(stripped_str)one way is to use list comprehension to bring a for loop into one line
print(''.join([c for c in string if c not in characters]))
Output:Th qck brwn fx jmps vr th lzy dg.
if its not too much trouble would you be so kind as to give a quick explanation as to how your code executes? How it all fits together and how it works, I see there is a for loop, and a if statement which I am more or less familiar with by now, the .join seems very obvious. I have not yet heard about the "not in" which follows the if statement. It also sounds very obvious as to what it does but I would really love to hear how exactly it works so I can possibly replicate it in the future. It runs perfectly but I would love to understand it perfectly too if a short explanation is not too much of a problem for you. This one liner for loops is quite foreign to me