Skip to content

Commit 251ba7c

Browse files
authored
Add files via upload
1 parent 92a577a commit 251ba7c

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
def main():
2+
3+
#list not in list
4+
vowels = ['a', 'u', 'e', 'i', 'o', 'A', 'U', 'E', 'I', 'O']
5+
text = "https://vitoshacademy.com is my blog."
6+
no_vowels = ''.join([x for x in text if x not in vowels])
7+
print(no_vowels)
8+
9+
#print every second letter
10+
every_second = text[::2]
11+
print(every_second)
12+
every_second = "".join([x for i, x in enumerate(text) if i % 2 == 1])
13+
print(every_second)
14+
15+
#list in list
16+
only_vowels = "".join([x for x in text if x in vowels])
17+
print(only_vowels)
18+
19+
#dictionary from a string
20+
letters = list(text)
21+
occurrences = {char: letters.count(char) for char in letters}
22+
print(occurrences)
23+
char_dict = {char: ord(char) for char in letters}
24+
print(char_dict)
25+
26+
#creation of 1D matrix:
27+
matrix1D = [j for j in range(100,105)]
28+
print(matrix1D)
29+
30+
#creation of a 2D matrix:
31+
matrix2D = [[j for j in range(4)] for i in range(10)]
32+
print(matrix2D)
33+
34+
#creation of a 3D matrix:
35+
matrix3D = [[[j for j in range(10,12)] for i in range(2)] for z in range(2)]
36+
print(matrix3D)
37+
38+
#2D matrix to list:
39+
flattened = [num for sublist in matrix2D for num in sublist]
40+
print(flattened)
41+
42+
#numbers, divisable by a set of other numbers
43+
numbers = [num for num in range(100, 150)]
44+
set_of_other_numbers = [num for num in range(2, 20)]
45+
divisable = [num for num in numbers if any([num % x == 0 for x in set_of_other_numbers])]
46+
print("divisable: {0}\n".format(divisable))
47+
48+
#numbers, non divisable by a set of other numbers
49+
non_divisable = [num for num in numbers if all([num % x != 0 for x in set_of_other_numbers])]
50+
print(non_divisable)
51+
52+
#numbers, non divisable by a set of other numbers, simple
53+
non_divisable = [num for num in numbers if num not in divisable]
54+
print(non_divisable)
55+
56+
if __name__ == "__main__":
57+
main()

0 commit comments

Comments
 (0)