Friday, October 5, 2018

Introvert or Extrovert

When you laugh a little loud, you are ill-mannered and when you laugh a little less, you are shy. Our social structures have made it a little complex for our Generation-Y aka millennial to grasp and apply these norms.Especially in context of Nepal, it is even more difficult to grow as a child; Because not only your parents, but also your neighbors, relatives and even friend's parents are watchdogs of your mannerism.Besides, there is this whole  decade long phenomenon and worshiper of discipline called school. The sad part, no child can escape it.I mean who as a scholar haven't heard this, " Does your parents teach this?" at school and "This is what you learn at school ?" at home .I believe every single of us.First of all please make sure who teaches what. This will make the life of a child more easier.Here, i am not trying to put blame on either of them. I couldn't have been grown up better and neither could have been educated better.So, both my parents and school have grabbed A+ on their transcripts.If allowed, i would give some partial credit to my neighbors and relatives as well.However, my problem is with the overall system and culture.

I cannot draw a conclusion representing my age group but i am trying to put my own perspective and experience.



Tuesday, September 18, 2018

4. Median of Two Sorted Arrays(Leetcode) Accepted solution

class Solution:
def findMedianSortedArrays(self,l1,l2):
sorted_new_list = l1 + l2
sorted_new_list.sort()
val = len(sorted_new_list)
if (val % 2 != 0):
return float(sorted_new_list[val //2])
else:
num1 = sorted_new_list[val//2 -1]
num2 = sorted_new_list [val//2]
return (num1 +num2 )/2
a = Solution()
print(a.findMedianSortedArrays([1,2,3,4,5] ,[6,7,8,9]))

Monday, September 17, 2018

leetcode problem2 (brute force) not all test cases passed

class Solution:
  def lengthOfLongestSubstring(self, s):
    if len(s) == 0:
      return 1
    else:
        self.l = ''
        self.count = 0
        self.mlist = []
        length =0
        for i in s:
            if i not in self.l:
                self.l += i
                self.count +=1
            elif i in self.l:
                self.mlist.append(self.count)
                self.count =0
                self.l = ''
                self.l +=i
                self.count +=1
            #return max(self.mlist)
            for i in self.mlist:
                if i > length:
                    length = i
            return length

a = Solution()
print(a.lengthOfLongestSubstring(""))

Tuesday, September 11, 2018

Leetcode problem1 brute force

class Solution:
def twoSum(self,nums, target):
thisdict = {}
#new_list = []
for i in range(0,len(nums)):
thisdict[nums[i]] = i
for i in thisdict:
rem = target - i
if rem in thisdict and rem != i:
return[thisdict[i],thisdict[rem] ]
a = Solution()
print(a.twoSum([3,3],6)) # It doesn't satisfy this use case

Data science class statisctisc

''def mean(x):
sum = 0
avg = 0

try:
for i in x:
sum+= i
avg = sum /len(x)
print(avg)
except ZeroDivisionError:
print("Division by zero error")
mean([])'''

import math
def mean(x):
return sum(x)/len(x) if len(x) is not 0 else 0
print(mean([1,2,3,5]))

def de_mean(x_list):
return abs(x_list[i]-mean(x_list[i]) for i in range(len(x_list)
print(de_mean([1,2,3,4,5]))







Tuesday, September 4, 2018

Python Data visualization, (Applied Data Science Class)

#sample code for plotting a bar diagram

import matplotlib.pyplot as plt
movies = ["Annie Hall", "Ben-Hur", "Casablanca", "Gandhi", "West Side Story"]
num_oscars = [5,11,3, 8, 10]
xs = [i + 0.1 for i, _ in enumerate(movies)]
plt.bar(xs, num_oscars)
plt.ylabel("# of Academy Awards")
plt.title("My favorite movies")
plt.xticks([i + 0.5 for i, _ in enumerate(movies)], movies)
plt.show()




#Create a Histogram of 1000 random grades

from collections import Counter
import matplotlin
matplotlib.use("Agg")
import matplotlib
grades =[]
#create a list of 1000 random grades between 0 and 100
decile = lamda grade:grade // 10 *10
histogram = COunter(decile(grade) for grade in grades)
plt.bar([x-4 for x n histogram.keys()], histogram.values(), 8)
plt.axis([-5, 105, 0, 5])
plt.xticks([10 * i for i in range(11)])
plt.xlabel("Decile")
plt.ylabel("# of Students")
plt.title("Distribution of the grades")
plt.savefig("histogram.png")

Saturday, August 4, 2018

Simply Me


Life, the word itself is wordplay, a really interesting one.At once your mother says "Why don't you ever think about your life." and on the same day your friend mocks you " Why do you think a lot about your life."Basically, it all resides between that thinking too less and too much. Doesn't it seem so simple. Alas,we all wish it was ! Don't we ?