This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
get_directory = input("Enter path : ") | |
d = os.listdir(get_directory) | |
for dir in d: | |
currrent_path = os.path.abspath(dir) | |
print(currrent_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def count_occurrence(values, to_find): | |
number_of_occurrences = 0 | |
for v in range(len(values)): | |
if values[v] == to_find: | |
number_of_occurrences += 1 | |
return number_of_occurrences | |
values = [1, 2, 3, 3] | |
check_for_threes = count_occurrence(values, 3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def reverse(lines): | |
return "Reverse order: " + lines[::-1] + "\n" + "Normal Order: " + lines | |
print(reverse("I am printing a sentence in reverse order")) | |
print(reverse("printing strings in reverse order using python")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib.request, urllib.parse, urllib.error | |
from urllib.request import urlopen | |
from bs4 import BeautifulSoup | |
import ssl | |
# Ignore SSL certificate errors | |
ctx = ssl.create_default_context() | |
ctx.check_hostname = False | |
ctx.verify_mode = ssl.CERT_NONE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Python Regular Expression Quick Guide | |
^ Matches the beginning of a line | |
$ Matches the end of the line | |
. Matches any character | |
\s Matches whitespace | |
\S Matches any non-whitespace character | |
* Repeats a character zero or more times | |
*? Repeats a character zero or more times | |
(non-greedy) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add=dict() | |
name = input("Enter file:") | |
handle = open(name,'r') | |
for mail in handle: | |
if not mail.startswith('From '): continue | |
text=mail.split() | |
text=text[1] | |
add[text]=add.get(text,0)+1 | |
print(text, add[text]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Background | |
Imagine you're working at Facebook and your job is to implement the "Like" functionality. | |
When a user clicks the "Like" button below a post, the button is highlighted (to indicate that it is selected) and the number of likes is increased. | |
You're going to implement this feature in Angular and for that you'll need to create a component. This component is a TypeScript class that encapsulates the data for rendering the like button (eg: the number of likes, and whether the button is in the on/off state). It also responds to user actions. So, when the user clicks the "Like" button, the number of likes should be increased and the button should be in the "selected/on" state. If the user clicks the button again, the number of likes should be decreased and the button should be in the "unselected" state. | |
Spec | |
For the purpose of this exercise, forget about the HTML. Your focus should be purely on defining a TypeScript class with the right members (fields, properties, methods, constructor). | |
Allow the c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pygame #used to create video games | |
import tkinter as tkr #used to develop GUI | |
from tkinter.filedialog import askdirectory #it permit to select dir | |
import os #it permits to interact with the operating system | |
music_player = tkr.Tk() | |
music_player.title("Ayub Technologies Player") | |
music_player.geometry("450x350") | |
directory = askdirectory() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def generateotp(): | |
otp_found = 0 | |
while otp_found == 0: | |
Endpoint = "https://api.redacted.com/v3/users/login" | |
#Generate new OTP Post data to be sent | |
payload = {"uemail":"","password":"","umobile":"0720619878"} | |
headers = {"temptoken": "8fa1db6aa4652f6124062f9ca1d2c5b1a6da199f", "Connection": "close"} | |
#Generating New otp | |
r = requests.post(url = Endpoint, data=json.dumps(payload), headers=headers) | |
soup = BS(r.text, "html.parser") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Open the file mbox-short.txt and read it line by line. When you find a line that starts with 'From ' like the following line: | |
# From stephen.marquard@uct.ac.za Sat Jan 5 09:14:16 2008 | |
# You will parse the From line using split() and print out the second word in the line (i.e. the entire address of the person who sent the message). Then print out a count at the end. | |
# Hint: make sure not to include the lines that start with 'From:'. Also look at the last line of the sample output to see how to print the count. | |
# You can download the sample data at http://www.py4e.com/code3/mbox-short.txt | |
#MY SOLUTION | |
fh = open(fname) |