00
00.py
s = "stressed"
print(s[::-1])
Résultat d'exécution
desserts
01
01.py
s = "Patatoku Kashii"
print(s[::2])
Résultat d'exécution
Voiture Pat
02
02.py
ret = ''
s1 = 'Voiture Pat'
s2 = 'Taxi'
s = ''.join([a + b for a, b in zip(s1, s2)])
print(s)
Résultat d'exécution
Patatoku Kashii
03
03.py
s = "Now I need a drink, alcoholic of course, after the heavy lectures involving quantum mechanics."
s = s.replace(',','')
s = s.replace('.', '')
l = s.split()
ret = [len(s) for s in l]
print(ret)
Résultat d'exécution
[3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9]
04
04.py
s = "Hi He Lied Because Boron Could Not Oxidize Fluorine. New Nations Might Also Sign Peace Security Clause. Arthur King Can."
i = 1
n = (0, 4, 5, 6, 7, 8, 14, 15, 18)
d = {i: word[0:1] if i in n else word[0:2] for i, word in enumerate(s.split())}
print(d)
Résultat d'exécution
{0: 'H',
1: 'He',
2: 'Li',
3: 'Be',
4: 'B',
5: 'C',
6: 'N',
7: 'O',
8: 'F',
9: 'Ne',
10: 'Na',
11: 'Mi',
12: 'Al',
13: 'Si',
14: 'P',
15: 'S',
16: 'Cl',
17: 'Ar',
18: 'K',
19: 'Ca'}
05
05.py
def ngram(s, n):
return [s[i:i+n] for i, _ in enumerate(list(s))]
print(ngram("I am an NLPer", 2))
Résultat d'exécution
['I ', ' a', 'am', 'm ', ' a', 'an', 'n ', ' N', 'NL', 'LP', 'Pe', 'er', 'r']
06
06.py
def ngram(s, n):
return {s[i:i+n] for i, _ in enumerate(list(s))}
s1 = "paraparaparadise"
s2 = "paragraph"
X = ngram(s1, 2)
Y = ngram(s2, 2)
print("X | Y :", X | Y)
print("X & Y :", X & Y)
print("X - Y :", X - Y)
print("se" in X)
print("se" in Y)
Résultat d'exécution
X | Y : {'ra', 'h', 'gr', 'pa', 'ph', 'ap', 'ar', 'ad', 'di', 'is', 'se', 'ag', 'e'}
X & Y : {'pa', 'ap', 'ra', 'ar'}
X - Y : {'ad', 'di', 'se', 'is', 'e'}
True
False
07
07.py
def template(x, y, z):
return str(x) + "de temps" + y + "Est" + str(z)
print(template(x=12, y="Température", z=22.4))
Résultat d'exécution
'La température à 12 heures est de 22.4'
08
08.py
def cipher(s):
return ''.join([chr(219-ord(s1)) if s1.islower() else s1 for s1 in s])
s = "Are you sure?"
s_encrypted = cipher(s)
print(s_encrypted)
Résultat d'exécution
Aiv blf hfiv?
09
09.py
import random
def typoglycemia(s):
return ' '.join([s1 if len(s1)<=4 else shuffle_string(s1) for s1 in s.split()])
def shuffle_string(s):
return s[0] + ''.join(random.sample(s[1:-1], len(s[1:-1])))+ s[-1]
s = "I couldn't believe that I could actually understand what I was reading : the phenomenal power of the human mind ."
print(typoglycemia(s))
Résultat d'exécution
I c'odulnt bievele that I colud aatcluly uasdnnertd what I was rdeaing : the poenhaenml poewr of the hamun mind .
Recommended Posts