[Solved] When should we use split() in Python?

I don’t understand the confusion. The split() function return a list of all subparts of your string by removing all occurences of the given argument. For example, if you have the following string : “Hello world!” and split this one by split(“o”) then your output will be : [“Hell”, ” w”, “rld!”] With a code: … Read more

[Solved] Extract only first match using python regular expression [duplicate]

Pretty simple: In [8]: course_name Out[8]: ‘Post Graduate Certificate Programme in Retail Management (PGCPRM) (Online)’ In [9]: print re.sub(‘\([A-Z]+\)\s*’, ”, course_name) Post Graduate Certificate Programme in Retail Management (Online) In [17]: print re.search(‘\(([A-Z]+)\)\s*’, course_name).groups()[0] PGCPRM 0 solved Extract only first match using python regular expression [duplicate]

[Solved] Running a django project with documentation based in linux on windows

I’m on Windows 10. If you’re not opposed to using Windows Command Prompt, here are the steps to running this project. I don’t use Powershell but if you must, see Powershell note at bottom of my answer. Go here: https://github.com/sajib1066/django-event-management Grab this clone link: https://github.com/sajib1066/django-event-management.git Open Windows CMD prompt. Change directory to a place on … Read more

[Solved] Search in text file and save in Excel

It’s quite easy using pandas and a dict: with open(‘file.txt’, ‘r’) as f: lines = f.readlines() students = [] student = {} for line in lines: if ‘:’ in line: student[‘id’] = line.split(‘:’)[0] elif ‘name’ in line: student[‘Name’] = line.split(‘=’)[1].replace(‘\n’,”) elif ‘Age’ in line: student[‘Age’] = line.split(‘=’)[1].replace(‘\n’,”) elif ‘Grade’ in line: student[‘Grade’] = line.split(‘=’)[1].replace(‘\n’,”) students.append(student) … Read more

[Solved] Need to find second maximum number in the list. All the details pasted below in the body. Please assist

An easy implementation would be to do something like: if len(set(input)) == 1: print(‘not present’) else: sorted(set(input))[-2] Take a look at Get the second largest number in a list in linear time for other implementations. 6 solved Need to find second maximum number in the list. All the details pasted below in the body. Please … Read more

[Solved] Creating a class in python with several methods [closed]

Replace num1 and num2 with num3 and num4. class fraction: def __init__(self,num1,num2,num3,num4): self.num1=num1 self.num2=num2 self.num3=num3 self.num4=num4 def addition(self): print(self.num1+self.num2) return self.num1+self.num2 def sub(self): print(self.num1+self.num2) return self.num1+self.num2 def div(self): print(self.num1/self.num2) return self.num1/self.num2 def mul(self): print(self.num1*self.num2) return self.num1*self.num2 def reminder(self): print(self.num1%self.num2) return self.num1%self.num2 if __name__ ==”__main__”: object=fraction(1,2,3,4) object.addition() object.reminder() 0 solved Creating a class in python with … Read more

[Solved] If I want something to consistently be happening while the rest of my program is still running in Python, what do I do? [closed]

Use threading: import threading def interest(): while True: print(‘interest is running’) d = threading.Thread(target=interest) d.setDaemon(True) d.start() print(‘Your main job is here’) 1 solved If I want something to consistently be happening while the rest of my program is still running in Python, what do I do? [closed]

[Solved] Bubble sort function in Python

for passnum in range(len(alist)-1,0,-1): Per the range function documentation: len(alist) – 1 is the length of the list (8) minus one (7). It represents some “starting” number. 0 represents the “stopping” number. -1 represents the “step” number. These come together in range(len(alist) – 1, 0, -1) to say “count from 7 to 0, backwards – … Read more