Skip to main content

combine values

0 likes • Nov 19, 2022 • 0 views
Python
Loading...

More Python Posts

hex to rgb

0 likes • Nov 19, 2022 • 2 views
Python
def hex_to_rgb(hex):
return tuple(int(hex[i:i+2], 16) for i in (0, 2, 4))
hex_to_rgb('FFA501') # (255, 165, 1)

Find URL in string

0 likes • Nov 19, 2022 • 0 views
Python
# Python code to find the URL from an input string
# Using the regular expression
import re
def Find(string):
# findall() has been used
# with valid conditions for urls in string
regex = r"(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'\".,<>?«»“”‘’]))"
url = re.findall(regex,string)
return [x[0] for x in url]
# Driver Code
string = 'My Profile: https://codecatch.net'
print("Urls: ", Find(string))

Untitled

0 likes • Apr 21, 2023 • 0 views
Python
print("hellur")

two-digit integer

0 likes • Feb 26, 2023 • 0 views
Python
#You are given a two-digit integer n. Return the sum of its digits.
#Example
#For n = 29 the output should be solution (n) = 11
def solution(n):
return (n//10 + n%10)

LeetCode Flood Fill

0 likes • Oct 15, 2022 • 0 views
Python
class Solution(object):
def floodFill(self, image, sr, sc, newColor):
R, C = len(image), len(image[0])
color = image[sr][sc]
if color == newColor: return image
def dfs(r, c):
if image[r][c] == color:
image[r][c] = newColor
if r >= 1: dfs(r-1, c)
if r+1 < R: dfs(r+1, c)
if c >= 1: dfs(r, c-1)
if c+1 < C: dfs(r, c+1)
dfs(sr, sc)
return image

Distinct Primes Finder > 1000

0 likes • Nov 18, 2022 • 3 views
Python
primes=[]
products=[]
def prime(num):
if num > 1:
for i in range(2,num):
if (num % i) == 0:
return False
else:
primes.append(num)
return True
for n in range(30,1000):
if len(primes) >= 20:
break;
else:
prime(n)
for previous, current in zip(primes[::2], primes[1::2]):
products.append(previous * current)
print (products)