Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d9c3013

Browse filesBrowse files
authored
add file
1 parent 4d00962 commit d9c3013
Copy full SHA for d9c3013

File tree

2 files changed

+18
-0
lines changed
Filter options

2 files changed

+18
-0
lines changed

‎list_comprehension.py

Copy file name to clipboard
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
n = 20
2+
print([num for num in range(n)])
3+
# [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
4+
print([num for num in range(1, n + 1)])
5+
# [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
6+
print([num for num in range(1, n, 2)])
7+
# [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
8+
print([num if num%3==0 else "nan" for num in range(10)])
9+
# [0, 'nan', 'nan', 3, 'nan', 'nan', 6, 'nan', 'nan', 9]
10+
print([num for num in range(n) if num%4==0])
11+
# [0, 4, 8, 12, 16]

‎reverse_string.py

Copy file name to clipboard
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
a = "hello python"
2+
''' reverse string '''
3+
print(a[::-1])
4+
# nohtyp olleh
5+
''' skip every second character '''
6+
print(a[::2])
7+
# hlopto

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.