TL;DR —
The rearrange1.py function is used to rearrange names in python. The rearrange2.py method is used for adding a name to a list of names. The name rearrange_name function takes a name and returns a string. It can also be used to add a number to a name.
Command:
$ cat rearrange1.py
Code output:
#!/usr/bin/env python3
import re
def rearrange_name(name):
result = re.search(r"^([\w .]*), ([\w .]*)$", name)
if result == None:
return name
return "{} {}".format(result[2], result[1])
Command:
$ cat rearrange2.py
Code output:
#!/usr/bin/env python3
import re
def rearrange_name(name):
result = re.search(r"^([\w .-]*), ([\w .-]*)$", name)
if result == None:
return name
return "{} {}".format(result[2], result[1])
Command:
$ diff rearrange1.py rearrange2.py
Code output:
6c6
< result = re.search(r"^([\w .]*), ([\w .]*)$", name)
---
> result = re.search(r"^([\w .-]*), ([\w .-]*)$", name)
Command:
$ diff validations1.py validations2.py
Code output:
5c5,6
< assert (type(username) == str), "username must be a string"
--
> if type(username) != str:
> raise TypeError("username must be a string")
11a13,15
> return False
> # Usernames can't begin with a number
> if username[0].isnumeric():
Command:
$ diff -u validations1.py validations2.py
Code output:
--- validations1.py 2019-06-06 14:28:49.639209499 +0200
+++ validations2.py 2019-06-06 14:30:48.019360890 +0200
@@ -2,7 +2,8 @@
def validate_user(username, minlen):
- assert type(username) == str, "username must be a string"
+ if type(username) != str:
+ raise TypeError("username must be a string")
if minlen < 1:
raise ValueError("minlen must be at least 1")
@@ -10,5 +11,8 @@
return False
if not username.isalnum():
return False
+ # Usernames can't begin with a number
+ if username[0].isnumeric():
+ return False
return True
[story continues]
Written by
@artwalker
Passionate about Crafting Intelligent OS & Pioneering TinyML Applications for Resource-Constrained Devices
Topics and
tags
tags
git|github|diffing-files|how-to-diff-files|what-is-diffing-files|diff-files-tutorial|git-for-beginners|how-do-i-diff-files
This story on HackerNoon has a decentralized backup on Sia.
Transaction ID: MAeKCsEZW_sPy7iNqajKhxCEtzELKqhT6XM-aYM5jQo
