Skip to content

Commit 6389e3e

Browse files
Merge pull request geekcomputers#629 from ishitagupta8720/master
added comments
2 parents 7303a64 + 58bf5c9 commit 6389e3e

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

Binary_search.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
def binarySearch(arr, l, r, x):
44
while l <= r:
55

6-
mid = l + (r - l) / 2;
6+
mid = l + (r - l) / 2; #extracting the middle element of the array
77

88
# Check if x is present at mid
99
if arr[mid] == x:
1010
return mid
1111

1212
# If x is greater, ignore left half
1313
elif arr[mid] < x:
14-
l = mid + 1
14+
l = mid + 1 #l is initialised to the rightmost element of the middle so that the search could be started from there the next time
1515

1616
# If x is smaller, ignore right half
1717
else:
18-
r = mid - 1
18+
r = mid - 1 #r is initialised to the leftmost element of the middle so that the search goes till there only the next time
1919

2020
# If we reach here, then the element was not present
2121
return -1
@@ -25,12 +25,14 @@ def binarySearch(arr, l, r, x):
2525
if __name__ == "__main__":
2626
# User input array
2727
print("Enter the array with comma separated in which element will be searched")
28-
arr = map(int, input().split(","))
28+
arr = map(int, input().split(",")) #the input array will of int type with each element seperated with a comma due to the split fucntion
29+
#map function returns a list of results after applying the given function to each item
2930
x = int(input("Enter the element you want to search in given array"))
3031

3132
# Function call
3233
result = binarySearch(arr, 0, len(arr) - 1, x)
33-
34+
35+
#printing the output
3436
if result != -1:
3537
print("Element is present at index {}".format(result))
3638
else:

CountMillionCharacter.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"""
99
import re
1010

11-
pattern = re.compile("\W")
11+
pattern = re.compile("\W") #re is used to compile the expression more than once
12+
#wordstring consisting of a million characters
1213
wordstring = '''SCENE I. Yorkshire. Gaultree Forest.
1314
Enter the ARCHBISHOP OF YORK, MOWBRAY, LORD HASTINGS, and others
1415
ARCHBISHOP OF YORK
@@ -293,17 +294,17 @@
293294
Before, and greet his grace: my lord, we come.
294295
Exeunt'''
295296

296-
wordlist = wordstring.split()
297+
wordlist = wordstring.split() #splits each word with a space
297298

298299
for x, y in enumerate(wordlist):
299-
special_character = pattern.search(y[-1:])
300+
special_character = pattern.search(y[-1:]) #searches for a pattern in the string
300301
try:
301-
if special_character.group():
302+
if special_character.group(): #returns all matching groups
302303
wordlist[x] = y[:-1]
303304
except:
304305
continue
305306

306-
wordfreq = [wordlist.count(w) for w in wordlist]
307+
wordfreq = [wordlist.count(w) for w in wordlist] #counts frequency of a letter in the list
307308

308309
print("String\n {} \n".format(wordstring))
309310
print("List\n {} \n".format(str(wordlist)))

Day_of_week.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Python program to Find day of
22
# the week for a given date
3-
import calendar
4-
import datetime
3+
import calendar #module of python to provide useful fucntions related to calendar
4+
import datetime # module of python to get the date and time
55

66

77
def findDay(date):
8-
born = datetime.datetime.strptime(date, '%d %m %Y').weekday()
9-
return (calendar.day_name[born])
8+
born = datetime.datetime.strptime(date, '%d %m %Y').weekday() #this statement returns an integer corresponding to the day of the week
9+
return (calendar.day_name[born]) #this statement returns the corresponding day name to the integer generated in the previous statement
1010

1111

1212
# Driver program
13-
date = '03 02 2019'
14-
print(findDay(date))
13+
date = '03 02 2019' #this is the input date
14+
print(findDay(date)) # here we print the final output after calling the fucntion findday

0 commit comments

Comments
 (0)