# coding: utf-8
1+2
print(123)
for i in [1,2,3]:
    print(i)
    print(i+2)
    
get_ipython().run_line_magic('ls', '')
get_ipython().run_line_magic('ls', '')
get_ipython().run_line_magic('clear', '')
get_ipython().run_line_magic('cat', '> pokus.txt')
get_ipython().run_line_magic('cd', 'tmp')
get_ipython().run_line_magic('pinfo', ' print')
import
import sys
get_ipython().run_line_magic('pinfo', ' sys')
get_ipython().run_line_magic('time', 'print(123)')
def bench(size):
    acc = ''
    for i in range(size):
        acc += str(i)
        
get_ipython().run_line_magic('time', 'bench(1000)')
get_ipython().run_line_magic('time', 'bench(10000)')
get_ipython().run_line_magic('time', 'bench(100000)')
get_ipython().run_line_magic('time', 'bench(1000000)')
def bench2(size):
    acc = ''
    for i in range(size):
        acc = str(i) + acc
        
        
get_ipython().run_line_magic('time', 'bench2(100)')
get_ipython().run_line_magic('time', 'bench2(1000)')
get_ipython().run_line_magic('time', 'bench2(10000)')
get_ipython().run_line_magic('time', 'bench2(100000)')
a="Hi John"
b='Hi Mary'
b='Hi Mary"'
print(b)
print("Hi"")
print("Hi\"")
print("Hi\\\"")
print(r'\')
print(r"\")
print(r"\n")
print("\n")
name = 'John'
print('Hi '+name)
print('Hi '+name+'!')
print('Hi %s!'%name)
print('Hi {}!'.format(name))
print(f'Hi {name}!')
i = 153
print(f'Hi {i}!')
multiline = """first line
second line
third line"""
print(multiline)
multiline = "first line\nsecond\n"
print(multiline)
"John"*5
5*"John"
"John".upper()
"John".isupper()
"John".islower()
"John".istitle()
"alpha".title()
sample = "This is a beautiful UFAL course on NLP"
sample.split()
for word in sample.split():
    if word.isupper():
        print(word)
        
[word for word in sample.split()]
[word.upper() for word in sample.split()]
["["+word+"]" for word in sample.split()]
[word for word in sample.split() if word.isupper()]
" ".join([word for word in sample.split() if word.isupper()])
get_ipython().system('pwd')
get_ipython().run_line_magic('mkdir', 'strings')
get_ipython().run_line_magic('mkdir', 'strings2')
get_ipython().run_line_magic('cd', 'strings2')
get_ipython().run_line_magic('cat', '> sample.txt')
get_ipython().system('echo "firstline\\nsecondline">sample2.txt')
get_ipython().run_line_magic('less', 'sample2.txt')
get_ipython().run_line_magic('man', 'echo')
fh = open('sample.txt')
fh
fh.read().splitlines()
fh = open('sample.txt')
lines = fh.readlines()
lines
lines = list(fh)
lines
fh = open('sample.txt')
lines = list(fh)
lines
for line fh:
    print(line)
for line in fh:
    print(line)
    
fh = open('sample.txt')
for line in fh:
    print(line)
    
get_ipython().run_line_magic('pinfo', ' print')
fh = open('sample.txt')
fh.read()
fh = open('sample.txt')
''.join(fh.readlines())
import sys
for line in sys.stdin:
    print(line)
    
sample
'is' in sample
sample.replace('This','It')
import re
re.search('.',sample)
re.findall('.',sample)
re.findall('a',sample)
sample
re.findall('is',sample)
re.findall('[aeiyou]',sample)
re.findall('is|are',sample)
re.findall('ea|ou',sample)
re.findall('[aeiyou]{2}',sample)
re.findall('[aeiyou]{2,}',sample)
re.findall('[aeiyou]+',sample)
re.findall('[aeiyou]+',sample,re.I)
re.findall('[A-Z]',sample)
re.findall('[A-Z]+',sample)
re.findall('[A-Z]+?',sample)
re.findall('\d',"This is number 5")
re.findall('\D',"This is number 5")
re.findall('\s',"This is number 5")
for mo in re.finditer('\S{3}',sample):
    print(str(mo.start))
    
for mo in re.finditer('\S{3}',sample):
    print(str(mo.start()))
    
    
samle
sample
for mo in re.finditer('\S{3,}',sample):
    print(str(mo.start()))
    
    
    
re.sub(r'(.{5})',r'\1\n',sample)
print(re.sub(r'(.{5})',r'\1\n',sample))
print(re.sub(r'(.{5,}) ',r'\1\n',sample))
print(re.sub(r'(.{5,}?) ',r'\1\n',sample))
text = 'John loves Mary, but whatever. What? Where!'
re.split(r'[[:punct:]]',text)
re.split(r'[,?:!.]',text)
import str
import string
string.punctuation
get_ipython().run_line_magic('save', 'stringsession.py ~0/')
