Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lab 03, task 7 #1

Open
sevinjyolchuyeva opened this issue Sep 27, 2017 · 2 comments
Open

Lab 03, task 7 #1

sevinjyolchuyeva opened this issue Sep 27, 2017 · 2 comments
Labels

Comments

@sevinjyolchuyeva
Copy link

sevinjyolchuyeva commented Sep 27, 2017

I wrote this task as below:
s='hey (come) go'
re.sub('[(].*?[)]', '', s)

The output is: 'hey go'

But if s='hey (come) go (flat)' then the 'go' is deleted too.
How can I write code that output should be 'hey go'

@DavidNemeskey
Copy link
Collaborator

I just tried the second substitution and it does what it ought to do: it returns 'hey go '. go would only be deleted if you omitted the question mark:

In [1]: import re

In [2]: re.sub('[(].*?[)]', '', 'hey (come) go (flat)')
Out[2]: 'hey  go '

In [3]: re.sub('[(].*[)]', '', 'hey (come) go (flat)')
Out[3]: 'hey '

@sevinjyolchuyeva
Copy link
Author

Yes, you are right :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants