Skip to content

Instantly share code, notes, and snippets.

@adi928
Created December 15, 2019 22:41
Show Gist options
  • Save adi928/c2d936ea654b16fd9ccc1b73ced17888 to your computer and use it in GitHub Desktop.
Save adi928/c2d936ea654b16fd9ccc1b73ced17888 to your computer and use it in GitHub Desktop.
Practicing python. Nothing to see here. Move on!
def per_octal(perm_string):
permStr = ""
res = 0
for i in range(len(perm_string)):
perm = perm_string[i]
if perm == 'r':
res += 4
elif perm == 'w':
res += 2
elif perm == 'x':
res += 1
elif perm == '-':
res += 0
if (i+1 % 3 == 0):
permStr = str(res)
res = 0
return int(permStr)
def tuple_slice(startIndex, endIndex, tup):
res = ""
resList = []
for ele in tup[startIndex:endIndex]:
resList.append(str(ele))
return (',').join(resList)
def change_date_format(dates):
resList = []
dateStr = ""
for date in dates:
dateStr = ""
form1 = []
form2 = []
form1 = date.split('/')
form2 = date.split('-')
if len(form1) == 3:
if len(form1[0]) == 4:
for ele in form1:
dateStr += ele
resList.append(dateStr)
else:
dateStr = form1[2] + form1[1] + form1[0]
resList.append(dateStr)
elif len(form2) == 3:
dateStr = form2[2] + form2[0] + form2[1]
resList.append(dateStr)
return resList
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment