Posts

Showing posts from January, 2021

Challenge - #53 - Set .union() Operation

  # Enter your code here. Read input from STDIN. Print output to STDOUT en =  int ( input ()) english =  set ( map ( int ,  input ().split())) fr =  int ( input ()) french =  set ( map ( int ,  input ().split())) print ( len (english.union(french)))

Challenge - #52 - Set .discard(), .remove(), & .pop()

n =  int ( input ()) s =  set ( map ( int ,  input ().split())) for  i  in   range ( int ( input ())):     inp =  input ()      if  inp ==  "pop" :         s.pop()      else :         command , value = inp.split()          if  command ==  "discard" :             s.discard( int (value))          else :             s.remove( int (value)) print ( sum (s))

Challenge - #51 - Word Order

  # Enter your code here. Read input from STDIN. Print output to STDOUT from  collections  import  OrderedDict od= OrderedDict() for  i  in   range ( int ( input ())):     word =  input ()      if  word  not   in  od:         od[word] =  1      else :         od[word] +=  1 print ( len (od)) print (*od.values())

Challenge - #50 - Collections.OrderedDict()

from  collections  import  OrderedDict od = OrderedDict() for  i  in   range ( int ( input ())):     item_name, blank , price =  input ().rpartition( ' ' )      if  item_name  not   in  od:         od[item_name] =  int (price)      else  :         od[item_name] +=  int (price) for  i  in  od.items():      print (*i)

Challenge - #49 - collections.namedtuple

  4 lines of  code  from  collections  import  namedtuple n =  int ( input ()) data = namedtuple( "data" , input ()) print ( sum ([ int (data(* input ().split()).MARKS)  for  i  in   range (n)])/n) easy to read code from  collections  import  namedtuple n =  int ( input ()) data = namedtuple( "data" , input ()) marks_lst = [] for  i  in   range (n):     marks =  int (data(* input ().split()).MARKS)     marks_lst.append(marks) print ( sum (marks_lst)/n)

Challenge - #48 - Incorrect Regex

  # Enter your code here. Read input from STDIN. Print output to STDOUT import  re for  i  in   range ( int ( input ())):      try  :         re. compile ( input ())          print ( True )      except  :          print ( False )