Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
1
1_homework_安晓东
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
安晓东
1_homework_安晓东
Commits
3f6ee173
Commit
3f6ee173
authored
Jan 17, 2019
by
“安晓东”
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
第五次作业
parent
f3127e80
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
115 additions
and
0 deletions
+115
-0
lession_5/Regular.py
+32
-0
lession_5/SortUtils.py
+37
-0
lession_5/__init__.py
+13
-0
lession_5/toGoatLatin.py
+33
-0
No files found.
lession_5/Regular.py
0 → 100644
View file @
3f6ee173
import
re
class
Regular
:
def
__init__
(
self
,
str_f
):
self
.
str_f
=
str_f
# 匹配所有的数字
def
get_numbers
(
self
):
return
re
.
findall
(
'
\
d'
,
self
.
str_f
)
# 匹配所有的邮箱
def
get_emails
(
self
):
ret
=
'[0-9a-zA-Z_]{0,19}@[0-9a-zA-Z_]{1,13}
\
.[com,cn,net]{1,3}$'
return
re
.
findall
(
ret
,
self
.
str_f
)
# 方法可以匹配出所有的ip
def
get_ips
(
self
):
rep
=
re
.
findall
(
'((?:(?:25[0-5]|2[0-4]
\
d|[01]?
\
d?
\
d)
\
.){3}(?:25[0-5]|2[0-4]
\
d|[01]?
\
d?
\
d))'
,
self
.
str_f
)
return
rep
# 方法能够匹配出所有的url,url可以以http开头、https开头、ftp开头
def
get_urls
(
self
):
ret
=
'[http,https,ftp]{1,5}://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*
\
(
\
),]|(?:
%
[0-9a-fA-F][0-9a-fA-F]))+'
return
re
.
findall
(
ret
,
self
.
str_f
)
if
__name__
==
'__main__'
:
s
=
Regular
(
'https://www.fdsafds$
%%
.com'
)
s1
=
Regular
(
'my mumber is 18268194892 and my email address is 289965734@qq.com,and my ip address is 192.168.1.1 and 255.666.555.222 and my url is https://www.weekfan.com and my phone home_number is 0734-6838533 and 020-85071966'
)
print
(
s1
.
get_ips
())
# print(s.get_numbers())
print
(
s
.
get_urls
())
lession_5/SortUtils.py
0 → 100644
View file @
3f6ee173
class
SortUtils
:
def
sort_s
(
self
,
lis
,
way
):
if
way
==
'bubble'
:
self
.
_bubble
(
lis
)
if
way
==
'quick'
:
self
.
_quick
(
lis
,
0
,
len
(
lis
)
-
1
)
def
_bubble
(
self
,
lis
):
for
i
in
range
(
len
(
lis
)
-
1
):
for
j
in
range
(
len
(
lis
)
-
1
-
i
):
if
lis
[
j
]
>
lis
[
j
+
1
]:
lis
[
j
],
lis
[
j
+
1
]
=
lis
[
j
+
1
],
lis
[
j
]
print
(
lis
)
return
lis
def
_quick
(
self
,
list_str
,
start_index
,
end_index
):
if
start_index
<
end_index
:
# 角标左侧小于右侧开始排序
i
,
basick
,
j
=
start_index
,
list_str
[
start_index
],
end_index
while
i
<
j
:
# 首先保证左侧的index比右侧的小
while
i
<
j
and
basick
<=
list_str
[
j
]:
# 基准比有侧的下表为(j)值小时,角标做左移
j
-=
1
while
i
<
j
and
basick
>=
list_str
[
i
]:
# 基准比左侧的下表为(i)值大时,角标右移
i
+=
1
list_str
[
i
],
list_str
[
j
]
=
list_str
[
j
],
list_str
[
i
]
print
(
"i="
+
str
(
i
)
+
"&&&"
+
"j="
+
str
(
j
)
+
"$$$"
+
"sort_list="
+
str
(
list_str
))
list_str
[
start_index
],
list_str
[
i
]
=
list_str
[
i
],
list_str
[
start_index
]
# 当i=j时,将基准值与下标为i或者j的值交换位置
self
.
_quick
(
list_str
,
start_index
,
i
-
1
)
# 取i=j的下标左侧的值在执行
self
.
_quick
(
list_str
,
i
+
1
,
end_index
)
if
__name__
==
'__main__'
:
s
=
SortUtils
()
s
.
sort_s
([
10
,
6
,
9
,
18
,
20
,
5
,
7
,
15
,
14
,
18
,
19
],
'quick'
)
# s.sort_s([10, 6, 9, 18, 20, 5, 7, 15, 14, 18, 19], 'bubble')
lession_5/__init__.py
0 → 100644
View file @
3f6ee173
import
re
a
=
'1324.231.432.1234,192.168.1.6,10.25.11.255这些信息中,哪些是ip呢?'
ret
=
re
.
findall
(
'((?:(?:25[0-5]|2[0-4]
\
d|[01]?
\
d?
\
d)
\
.){3}(?:25[0-5]|2[0-4]
\
d|[01]?
\
d?
\
d))'
,
a
)
print
(
ret
)
print
(
re
.
findall
(
"(?:(?:
\
d
\
.|
\
d{2}
\
.|1
\
d{2}
\
.|2[0-4]
\
d
\
.|25[0-5]
\
.){3}(?:25[0-5]|2[0-4]
\
d|[01]?
\
d?
\
d))"
,
a
))
a
=
"I speak Goat Latin"
s
=
a
.
split
(
' '
)
print
(
s
)
lession_5/toGoatLatin.py
0 → 100644
View file @
3f6ee173
def
toGoatLatin
(
S
):
list_s
=
S
.
split
(
' '
)
result
=
''
index
=
1
for
i
in
list_s
:
if
i
[
0
]
in
[
'a'
,
'e'
,
'i'
,
'o'
,
'u'
,
'A'
,
'E'
,
'I'
,
'O'
,
'U'
]:
i
=
i
+
'ma'
+
'a'
*
index
else
:
i
=
i
[
1
:]
+
i
[
0
]
+
'ma'
+
'a'
*
index
index
+=
1
result
+=
i
+
' '
return
result
print
(
toGoatLatin
(
"I speak Goat Latin"
))
#
#
# def toGoatLatin(S):
#
# vowel = ['a', 'e', 'i', 'o', 'u']
# temp = S.split()
# for i in range(len(temp)):
# if temp[i][0].lower() in vowel:
# temp[i] = temp[i] + 'ma' + 'a' * (i + 1)
# else:
# temp[i] = temp[i][1:] + temp[i][0] + 'ma' + 'a' * (i + 1)
# return " ".join(temp).strip()
# print(toGoatLatin("I speak Goat Latin"))
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment