Skip to content
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

Strings Solutions added (Python) #50

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
26 changes: 13 additions & 13 deletions Data Structures/01. Arrays/001. Arrays - DS.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Problem: https://www.hackerrank.com/challenges/arrays-ds/problem
# Score: 10
def reverseArray(arr):
result = arr[::-1]
return result
arrСount = int(input())
arr = list(map(int, input().rstrip().split()))
result = reverseArray(arr)
print(*result)
# Problem: https://www.hackerrank.com/challenges/arrays-ds/problem
# Score: 10


def reverseArray(arr):
result = arr[::-1]
return result


arrСount = int(input())
arr = list(map(int, input().rstrip().split()))
result = reverseArray(arr)
print(*result)
9 changes: 9 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MIT License

Copyright (c) 2022 - 2023 Mike Donaghy [CODING-Enthusiast9857]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
File renamed without changes.
8 changes: 8 additions & 0 deletions Python/Strings/alphabetRangoli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from string import ascii_lowercase as chars

def print_rangoli(size):
ans=[]
for i in range(size):
s='-'.join(chars[i:size])
ans.append((s[::-1]+s[1:]).center(4*size-3,'-'))
print('\n'.join(ans[:0:-1]+ans))
4 changes: 4 additions & 0 deletions Python/Strings/capitalize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def solve(s):
for i in s.split():
s = s.replace(i,i.capitalize())
return s
6 changes: 6 additions & 0 deletions Python/Strings/designerDoorMat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
N,M=map(int,input().split())
for i in range(1,N,2):
print((i*'.|.').center(M,'-'))
print("WELCOME".center(M,'-'))
for j in range(N-2,-1,-2):
print((j*'.|.').center(M,'-'))
6 changes: 6 additions & 0 deletions Python/Strings/findString.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def count_substring(string, sub_string):
c=0
for x in range(len(string)):
if string[x:].startswith(sub_string):
c+=1
return c
8 changes: 8 additions & 0 deletions Python/Strings/mergeTheTools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def merge_the_tools(string, k):
n=len(string)
for i in range(0,n,k):
s=''
for ele in string[i:i+k]:
if (ele not in s):
s+=ele
print(s)
18 changes: 18 additions & 0 deletions Python/Strings/minionGame.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
def minion_game(string):
player1 = 0
player2 = 0
str_len = len(string)
for i in range(str_len):
if string[i] in "AEIOU":
player1 += (str_len)-i
else :
player2 += (str_len)-i

if player1 > player2:
print("Kevin", player1)
elif player1 < player2:
print("Stuart",player2)
elif player1 == player2:
print("Draw")
else :
print("Draw")
3 changes: 3 additions & 0 deletions Python/Strings/splitAndJoin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def split_and_join(line):
line=line.split()
return "-".join(line)
10 changes: 10 additions & 0 deletions Python/Strings/stringFormatting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def print_formatted(number):
l1 = len(bin(number)[2:])

for i in range(1,number+1):
print(str(i).rjust(l1,' '),end=" ")
print(oct(i)[2:].rjust(l1,' '),end=" ")
print(((hex(i)[2:]).upper()).rjust(l1,' '),end=" ")
print(bin(i)[2:].rjust(l1,' '),end=" ")
print("")

8 changes: 8 additions & 0 deletions Python/Strings/stringValidators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
if __name__ == '__main__':
s = input()

print(any(c.isalnum() for c in s))
print(any(c.isalpha() for c in s))
print(any(c.isdigit() for c in s))
print(any(c.islower() for c in s))
print(any(c.isupper() for c in s))
2 changes: 2 additions & 0 deletions Python/Strings/swapcase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def swap_case(s):
return s.swapcase()
9 changes: 9 additions & 0 deletions Python/Strings/textWrap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import textwrap

def wrap(string, max_width):
return "\n".join([string[i:i+max_width] for i in range(0,len(string),max_width)])

if __name__ == '__main__':
string, max_width = input(), int(input())
result = wrap(string, max_width)
print(result)
File renamed without changes.
7 changes: 7 additions & 0 deletions Python/listComprehension.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
if __name__ == '__main__':
x = int(input())
y = int(input())
z = int(input())
n = int(input())

print([[a,b,c] for a in range(0,x+1) for b in range(0,y+1) for c in range(0,z+1) if a+b+c!=n])
22 changes: 22 additions & 0 deletions Python/lists.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
if __name__ == '__main__':
N = int(input())
c=[]
for i in range(N):
c.append(input().split())

result=[]
for i in range(N):
if c[i][0]=='insert':
result.insert(int(c[i][1]),int(c[i][2]))
elif c[i][0]=='print':
print(result)
elif c[i][0]=='remove':
result.remove(int(c[i][1]))
elif c[i][0]=='append':
result.append(int(c[i][1]))
elif c[i][0]=='pop':
result.pop()
elif c[i][0]=='sort':
result.sort()
elif c[i][0]=='reverse':
result.reverse()
9 changes: 9 additions & 0 deletions Python/nestedLists.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
if __name__ == '__main__':
marksheet=[]
for _ in range(int(input())):
name = input()
score = float(input())
marksheet.append([name,score])

sh = sorted(list(set([score for name, score in marksheet])))[1]
print('\n'.join([a for a,b in sorted(marksheet) if b == sh]))
5 changes: 5 additions & 0 deletions Python/tuples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if __name__ == '__main__':
n = int(input())
integer_list = map(int, input().split())
t=tuple(integer_list)
print(hash(t))