Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
String handling
#4
(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
Reply


Messages In This Thread
String handling - by YoungGrassHopper - Sep-14-2019, 10:30 AM
RE: String handling - by metulburr - Sep-14-2019, 10:41 AM
RE: String handling - by YoungGrassHopper - Sep-14-2019, 10:42 AM
RE: String handling - by YoungGrassHopper - Sep-15-2019, 07:02 AM
RE: String handling - by perfringo - Sep-15-2019, 07:32 AM
RE: String handling - by ndc85430 - Sep-15-2019, 07:34 AM
RE: String handling - by YoungGrassHopper - Sep-15-2019, 08:12 AM
RE: String handling - by snippsat - Sep-15-2019, 09:55 AM
RE: String handling - by YoungGrassHopper - Sep-15-2019, 12:01 PM
RE: String handling - by jefsummers - Sep-15-2019, 12:21 PM
RE: String handling - by YoungGrassHopper - Sep-15-2019, 12:33 PM
RE: String handling - by YoungGrassHopper - Sep-15-2019, 01:12 PM
RE: String handling - by newbieAuggie2019 - Sep-15-2019, 09:20 PM
RE: String handling - by perfringo - Sep-15-2019, 01:05 PM
RE: String handling - by perfringo - Sep-15-2019, 05:38 PM
RE: String handling - by YoungGrassHopper - Sep-15-2019, 08:28 PM
RE: String handling - by YoungGrassHopper - Sep-15-2019, 10:37 PM
RE: String handling - by jefsummers - Sep-16-2019, 12:47 AM
RE: String handling - by YoungGrassHopper - Sep-16-2019, 04:45 AM
RE: String handling - by perfringo - Sep-16-2019, 05:11 AM
RE: String handling - by YoungGrassHopper - Sep-16-2019, 05:23 AM
RE: String handling - by perfringo - Sep-16-2019, 06:09 AM
RE: String handling - by YoungGrassHopper - Sep-16-2019, 06:46 AM
RE: String handling - by buran - Sep-16-2019, 06:54 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Star python exception handling handling .... with traceback mg24 3 1,322 Nov-09-2022, 07:29 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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