Python Forum
Thread Rating:
  • 2 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Set Comprehension
#3
Just use your original set comprehension with first "text" replaced with "w" and without "()" after punctuation, as wavic posted.
cypher = {w.strip(punctuation) for w in text.split()}
String methods do not work in-place, so your original for loop did not remove punctuation at all.
Reply


Messages In This Thread
Set Comprehension - by Steven - Apr-13-2017, 09:18 PM
RE: Set Comprehension - by wavic - Apr-13-2017, 09:25 PM
RE: Set Comprehension - by zivoni - Apr-13-2017, 09:40 PM
RE: Set Comprehension - by Steven - May-26-2017, 03:12 PM

Forum Jump:

User Panel Messages

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