Skip to content

some erroe fix #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 25 additions & 29 deletions basic_commands.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,38 @@
>>> a = ['a', 'b', 'c', 'd', 'e']
>>> for index, item in enumerate(a): print index, item # enumerate function will generate an index for the item + item it self.
...
0 a
1 b
2 c
3 d
4 e



a = ['a', 'b', 'c', 'd', 'e']
for index, item in enumerate(a):
print(index, item) # enumerate function will generate an index for the item + item it self.

#convert a list to string:

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

Or if the list is of integers, convert the elements before joining them.
#Or if the list is of integers, convert the elements before joining them.

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



#FIND method

str.find(str2, beg=0 end=len(string))
str.find(str1, beg=0, end=len(str))

'''
Parameters
str2 -- This specifies the string to be searched.
beg -- This is the starting index, by default its 0.
end -- This is the ending index, by default its equal to the lenght of the string.

Return Value
This method returns index if found and -1 otherwise.
This method returns index if found and -1 otherwise.'''

str1 = "this is string example....wow!!!";
str2 = "exam";
str1 = "this is string example....wow!!!"
str2 = "exam"

# find function will print the position for the first character of the string if it's found!
print str1.find(str2);
print str1.find(str2, 10);
print str1.find(str2, 40);
print(str1.find(str2))
print( str1.find(str2, 10))
print(str1.find(str2, 40))

#15
#15
Expand All @@ -54,28 +46,32 @@

# Creates a list containing 5 lists initialized to 0
Matrix = [[0 for x in range(5)] for x in range(5)]
You can now add items to the list:

#You can now add items to the list:

Matrix[0][0] = 1
Matrix[4][0] = 5

print Matrix[0][0] # prints 1
print Matrix[4][0] # prints 5
print(Matrix[0][0]) # prints 1
print(Matrix[4][0]) # prints 5


if you have a simple two-dimensional list like this:
#if you have a simple two-dimensional list like this:

A = [[1,2,3,4],
[5,6,7,8]]
then you can extract a column like this:

#then you can extract a column like this:

def column(matrix, i):
return [row[i] for row in matrix]
Extracting the second column (index 1):

>>> column(A, 1)
#Extracting the second column (index 1):

column(A, 1)
[2, 6]
Or alternatively, simply:

>>> [row[1] for row in A]
#Or alternatively, simply:

[row[1] for row in A]
[2, 6]