Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 8th, 2012, 08:16 PM
Nick Wyden Nick Wyden is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 44 Nick Wyden Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 4 h 10 m 54 sec
Reputation Power: 0
Output_string

Hello again so I have this code that takes all the punctuation out of the input (this is from a python textbook) but my question is how does the program know what output_string is equal too

punctuation = "#()*+,-/:<=>?\@^_`{|}~[]"

print (" ")

print ("*****")

print (" ")

input_string = input (" Enter text string: ")

output_string = " "

space_flagged = False


for char in input_string:
if char == '.':
print (output_string)
output_string = ' '

elif char not in punctuation:
output_string += char
space_flagged = False

else:
if not space_flagged:
output_string += ' '
space_flagged = True

print (output_string)

I have tried just running bits of the code and when I do the program prints output_string as nothing. Also what is a flag?
Comments on this post
Lux Perpetua disagrees: code tags.

Reply With Quote
  #2  
Old October 8th, 2012, 11:07 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,348 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 7 h 35 m 46 sec
Reputation Power: 383
Book: Discard it.

flags: Just a variable name. Common meaning is the data is Boolean. True or False. Suppose you run a complicated algorithm and but merely want to know if a pattern was found. You'd "set a flag" or make sure to clear it. Or, to tell the regular expression search that you want to ignore case, you'd "set a flag".

Code:
import string
punctuation = set(string.punctuation)

def remove(Input,Set):
    return [a for a in Input if a not in Set]

''.join(remove('T;h....i:::s \'"i,s? a pun[ctu][[a)))ted string',punctuation)
__________________
[code]Code tags[/code] are essential for python code!

Reply With Quote
  #3  
Old October 9th, 2012, 06:44 PM
Nick Wyden Nick Wyden is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 44 Nick Wyden Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 4 h 10 m 54 sec
Reputation Power: 0
ah that makes sense but how does the program know what output_string is because the value if just empty quotes

Reply With Quote
  #4  
Old October 9th, 2012, 07:22 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,348 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 7 h 35 m 46 sec
Reputation Power: 383
look through the program you posted line by line. Some places you'll see
output_string += char
or
output_string= ' '

These statements change output_string
There's still another few places of
print(output_string)

I can't figure out why the book author would want to remove punctuation from a sentence, or why their algorithm happens to be the smartest way to do it.

On periods the program displays its current collection and a new line.

Sometimes it sticks in spaces.

Whatever. I still say "discard your book".

Reply With Quote
  #5  
Old October 10th, 2012, 02:26 AM
SuperOscar SuperOscar is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2007
Location: Joensuu, Finland
Posts: 403 SuperOscar User rank is Second Lieutenant (5000 - 10000 Reputation Level)SuperOscar User rank is Second Lieutenant (5000 - 10000 Reputation Level)SuperOscar User rank is Second Lieutenant (5000 - 10000 Reputation Level)SuperOscar User rank is Second Lieutenant (5000 - 10000 Reputation Level)SuperOscar User rank is Second Lieutenant (5000 - 10000 Reputation Level)SuperOscar User rank is Second Lieutenant (5000 - 10000 Reputation Level)SuperOscar User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 4 h 48 m 52 sec
Reputation Power: 65
Quote:
Originally Posted by b49P23TIvg
I can't figure out why the book author would want to remove punctuation from a sentence,


Really? I can think of several reasons That’s the way you begin when you want to read a text into a corpus of some kind.

I think the original script was meant the parse the text into words sentence by sentence, and that’s why periods are handled specially. Ugly coding though.
__________________
My armada: openSUSE 12.3 (home desktop, laptop, work desktop), Ubuntu 12.04 LTS (mini laptop), Debian GNU/Linux 7.0 (server), Mythbuntu 12.04 LTS (HTPC), Bodhi Linux 2.0 & Windows 7 Ultimate (test desktop), FreeBSD 9.1 (test server)

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Output_string

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap