2015年12月26日土曜日

開発環境

  • OS X El Capitan - Apple (OS)
  • Emacs (Text Editor)
  • Python 3.5 (プログラミング言語)

Automate the Boring Stuff with Python: Practical Programming for Total Beginners (Al Sweigart (著)、No Starch Press)のPart 2.(Automating Tasks)、Chapter 7.(Pattern Matching with Regular Expressions)、Practice Projects(Regex Version of strip())を解いてみる。

Practice Projects(Regex Version of strip())

コード(Emacs)

#!/usr/bin/env python3
#-*- coding: utf-8 -*-

import re

def strip(s, chars='\\s'):
    return re.search(r'({0})*(.*?)({0})*$'.format(chars), s).group(2)

pythons = ['python', '     python', 'python     ', '     python          ',
           'p y thon']
for s in pythons:
    print("'{0}': '{1}'".format(s, strip(s)))

for s in pythons:
    print("'{0}': '{1}'".format(s, strip(s, "ab")))

pythons = ['python', 'ababpython', 'pythonabab', 'abpythona', 'abpythonabpythnonab']
for s in pythons:
    print("'{0}': '{1}'".format(s, strip(s, "ab")))

入出力結果(Terminal, IPython)

$ ./sample2.py
'python': 'python'
'     python': 'python'
'python     ': 'python'
'     python          ': 'python'
'p y thon': 'p y thon'
'python': 'python'
'     python': '     python'
'python     ': 'python     '
'     python          ': '     python          '
'p y thon': 'p y thon'
'python': 'python'
'ababpython': 'python'
'pythonabab': 'python'
'abpythona': 'pythona'
'abpythonabpythnonab': 'pythonabpythnon'
$

21 コメント:

Turkey visa usaさんのコメント...

The information you provided is very useful, thank you very much for sharing useful information with us. You can apply for an online Turkey visa usa - If you are Planning a Trip to Turkey for business, tourism purpose.

emergency e visa Indiaさんのコメント...

Wow.. Very informative article thanks for sharing please keep it up.. In the case of emergency e visa India fees for US citizens it may be applicable some extra charges.

Willamさんのコメント...


I really appreciate your efforts, fantastic articles. The e-tourist visa India Is an online travel authorization which grants the foreign people to visit India.

匿名さんのコメント...

En son çıkan perde modelleri
sms onay
mobil ödeme bozdurma
Nft Nasil Alınır
Ankara evden eve nakliyat
Trafik sigortasi
DEDEKTÖR
web sitesi kurma
aşk kitapları

匿名さんのコメント...

smm panel
smm panel
iş ilanları
İNSTAGRAM TAKİPÇİ SATIN AL
hirdavatciburada.com
beyazesyateknikservisi.com.tr
Servis
TİKTOK JETON HİLE

Turkey visa application formさんのコメント...

Great content that provides quality knowledge with interesting facts is what I love to read. The Turkish visa application form can be filled online from virtually anywhere in the world, so visitors from anywhere in the world can obtain their visa via email.

sms onayさんのコメント...

Congratulations on your article, it was very helpful and successful. a2e30209e014700ef5777cc9af6c5724
website kurma
numara onay
website kurma

altın dedektörüさんのコメント...

Thank you for your explanation, very good content. 66e4bf5222e317e930484907ab71bea3
define dedektörü

evde iş imkanıさんのコメント...

Thanks for your article. 5e240d844a354cfcfc6560042b4971f3
evden iş imkanı

sportsbetさんのコメント...

Good content. You write beautiful things.
korsan taksi
hacklink
taksi
vbet
hacklink
sportsbet
mrbahis
mrbahis
vbet

mobil ödeme bahisさんのコメント...

Good text Write good content success. Thank you
tipobet
betpark
kibris bahis siteleri
poker siteleri
kralbet
betmatik
slot siteleri
bonus veren siteler

casino siteleriさんのコメント...

This post is on your page i will follow your new content.
sportsbet
mrbahis
casino siteleri
sportsbetgiris.net
sportsbet
mrbahis.co
mrbahis giriş
betgaranti.online
sportsbet giriş

ömerさんのコメント...

başakşehir
bayrampaşa
beşiktaş
beykoz
beylikdüzü
RGXVX

berkayさんのコメント...

edirne
antakya
aydın
muş
afyon

H27

canerさんのコメント...

https://saglamproxy.com
metin2 proxy
proxy satın al
knight online proxy
mobil proxy satın al
DSAD

how much is a Turkey visaさんのコメント...

Your insightful blog post brilliantly navigates through the labyrinth of ideas, shedding light on perspectives often overlooked. The seamless blend of eloquence and depth captivates readers, leaving them with a richer understanding. Your words are not just a collection of thoughts; they are a symphony of wisdom that resonates long after the last sentence.

Turkey visa requirements for canadian citizensさんのコメント...

Please keep up the fantastic work! It's not often that I come across a blog that combines informative content with such a delightful writing style. You have a true talent for crafting engaging and insightful posts, and I'm sure that your audience will continue to grow as more people discover your work. I'll be eagerly following along with your future content, always looking forward to the next article. Thank you for sharing your talents with us!

Popular Destination Sees Tourist Tax Increase in 2024さんのコメント...

A gem among blogs, yours radiates brilliance, and this post exemplifies that radiance. The graceful fusion of insights and eloquence forms a captivating story.

Turkey visa for Canadian prさんのコメント...

Your blog post crafts a mesmerizing tapestry of insights, seamlessly blending thoughtfulness and depth. The harmonious interplay between well-researched facts and personal reflections constructs a truly compelling narrative. Your unique voice and perspective bring a refreshing touch, elevating this read to exceptional heights. Eagerly anticipating more content that challenges and inspires.

India tourist visa applicationさんのコメント...

Exceptional work! Your blog masterfully captures the essence of the subject matter. I appreciate how you simplify intricate concepts into digestible content. Your writing style is engaging and informative, making the reading experience enjoyable. Looking forward to more insightful posts!

visa to Cameroonさんのコメント...

Hello! Wanted to mention how much I appreciate your unique take on this topic. Your insights are novel and provoke new thoughts! The way you explain intricate ideas simply is truly impressive. Your dedication is evident! Keep doing amazing work; eagerly awaiting your next post! Thanks for the incredible content—keep it up!

コメントを投稿