Skip to content

Commit 8452907

Browse files
committed
some erroe fix
1 parent 524af79 commit 8452907

File tree

1 file changed

+25
-29
lines changed

1 file changed

+25
-29
lines changed

basic_commands.py

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,38 @@
1-
>>> a = ['a', 'b', 'c', 'd', 'e']
2-
>>> for index, item in enumerate(a): print index, item # enumerate function will generate an index for the item + item it self.
3-
...
4-
0 a
5-
1 b
6-
2 c
7-
3 d
8-
4 e
9-
10-
11-
1+
a = ['a', 'b', 'c', 'd', 'e']
2+
for index, item in enumerate(a):
3+
print(index, item) # enumerate function will generate an index for the item + item it self.
124

135
#convert a list to string:
146

157
list1 = ['1', '2', '3']
168
str1 = ''.join(list1)
179

18-
Or if the list is of integers, convert the elements before joining them.
10+
#Or if the list is of integers, convert the elements before joining them.
1911

2012
list1 = [1, 2, 3]
2113
str1 = ''.join(str(e) for e in list1)
2214

2315

24-
2516
#FIND method
2617

27-
str.find(str2, beg=0 end=len(string))
18+
str.find(str1, beg=0, end=len(str))
2819

20+
'''
2921
Parameters
3022
str2 -- This specifies the string to be searched.
3123
beg -- This is the starting index, by default its 0.
3224
end -- This is the ending index, by default its equal to the lenght of the string.
3325
3426
Return Value
35-
This method returns index if found and -1 otherwise.
27+
This method returns index if found and -1 otherwise.'''
3628

37-
str1 = "this is string example....wow!!!";
38-
str2 = "exam";
29+
str1 = "this is string example....wow!!!"
30+
str2 = "exam"
3931

4032
# find function will print the position for the first character of the string if it's found!
41-
print str1.find(str2);
42-
print str1.find(str2, 10);
43-
print str1.find(str2, 40);
33+
print(str1.find(str2))
34+
print( str1.find(str2, 10))
35+
print(str1.find(str2, 40))
4436

4537
#15
4638
#15
@@ -54,28 +46,32 @@
5446

5547
# Creates a list containing 5 lists initialized to 0
5648
Matrix = [[0 for x in range(5)] for x in range(5)]
57-
You can now add items to the list:
49+
50+
#You can now add items to the list:
5851

5952
Matrix[0][0] = 1
6053
Matrix[4][0] = 5
6154

62-
print Matrix[0][0] # prints 1
63-
print Matrix[4][0] # prints 5
55+
print(Matrix[0][0]) # prints 1
56+
print(Matrix[4][0]) # prints 5
6457

6558

66-
if you have a simple two-dimensional list like this:
59+
#if you have a simple two-dimensional list like this:
6760

6861
A = [[1,2,3,4],
6962
[5,6,7,8]]
70-
then you can extract a column like this:
63+
64+
#then you can extract a column like this:
7165

7266
def column(matrix, i):
7367
return [row[i] for row in matrix]
74-
Extracting the second column (index 1):
7568

76-
>>> column(A, 1)
69+
#Extracting the second column (index 1):
70+
71+
column(A, 1)
7772
[2, 6]
78-
Or alternatively, simply:
7973

80-
>>> [row[1] for row in A]
74+
#Or alternatively, simply:
75+
76+
[row[1] for row in A]
8177
[2, 6]

0 commit comments

Comments
 (0)