FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
algorithm/even_odd.py at master · shell-develop/algorithm · GitHub
shell-develop
algorithm
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
algorithm
/
even_odd.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
29 lines (19 loc) · 573 Bytes
Breadcrumbs
algorithm
/
even_odd.py
Copy path
File metadata and controls
29 lines (19 loc) · 573 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#! /usr/bin/env python
#coding:utf-8
'''
#way1
def odd_even_sort(lst):
is_odd_number = lambda data:(data%2!=0)
tmp_list1 = [item for item in lst if is_odd_number(item)]
tmp_list2 = [item for item in lst if not is_odd_number(item)]
return tmp_list1+tmp_list2
if __name__=="__main__":
test_lst = [7,9,12,5,4,9,8,3,12,89]
print odd_even_sort(test_lst)
'''
#way2
def
odd
(
x
):
return
x
%
2
==
1
def
even
(
x
):
return
x
%
2
==
0
if
__name__
==
"__main__"
:
test_lst
=
[
7
,
9
,
12
,
5
,
4
,
9
,
8
,
3
,
12
,
89
]
print
filter
(
even
,
test_lst
)
+
filter
(
odd
,
test_lst
)
Back
|
FazBrowse Home
|
New Git URL