Open study

is now brainly

With Brainly you can:

  • Get homework help from millions of students and moderators
  • Learn how to solve problems with step-by-step explanations
  • Share your knowledge and earn points by helping other students
  • Learn anywhere, anytime with the Brainly app!

A community for students.

http://ideone.com/Pru2y I need help with a function that cuts off whitespace surrounding newline characters in strings. I've already got it working in Python but I know I can improve it. Funny thing is that on ideone, I have to subtract 1 from the 'newline' variable to get it working right whereas on my Python implementation (2.7.2) it works correctly without that line.

Computer Science
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Join Brainly to access

this expert answer

SEE EXPERT ANSWER

To see the expert answer you'll need to create a free account at Brainly

Have you looked at/studied regular expressions?
If you do not know regex, It may be simpler to use built-in functions: def trimspaces(s): nl = '\n' ss = s.split(nl) ssr = [] for x in ss: ssr.append(x.strip()) return nl.join(ssr) if you know list comprehensions, it is one-liner return '\n'.join([ x.strip() for x in s.split('\n')])
I knew there was something built-in that would do the trick.... in 1 line! thanks python has a regex library.... but I don't even know what a regex is :(

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

Regular Expressions are a pattern matching grammar. They're the basis of Perl. Not the easiest things to learn, but extremely powerful. I use them every day to filter log files and do various tasks. Definitely worth the effort of learning.

Not the answer you are looking for?

Search for more explanations.

Ask your own question