What do you want to save?
Add Code snippet
New code examples
-
Python 2022-03-17 07:10:05
what is composition in python
# It's when a class has a (is made-of) another class. # Example class Thing(object): def func(self): print("Function ran from class Thing().") class OtherThing(object): # Note that I don't use inheritance to get the func() fun... Add solution -
Python 2022-03-17 03:55:17
np.select with multiple conditions
conditions = [ df['gender'].eq('male') & df['pet1'].eq(df['pet2']), df['gender'].eq('female') & df['pet1'].isin(['cat', 'dog']) ] choices = [5,5] df['points'] = np.select(conditions, choices, default=0) print(df) gender pet1 ... Add solution -
Python 2022-03-17 02:55:09
Check if a string is lapindrome or not in Python
s=input() s1,s2='','' if(len(s)%2==0): s1=s[:len(s)//2] s2=s[len(s)//2:] else: s1=s[:len(s)//2] s2=s[len(s)//2+1:] l1=list(s1) l2=list(s2) l1.sort() l2.sort() s1=str(l1) s2=str(l2) if(s1==s2): print('YES') else: print('NO') Add solution -
Python 2022-03-17 02:55:04
Write a python program to find the longest words.
def longestword(filename): with open(filename,'r+') as f: words = f.read().split() max_len_word = max(words,key=len) max_len = len(max(words,key=len)) print('maximum lenth word in file :',max_len_word) print('lenth is : ',max_len) longestwor... Add solution