Collections.namedtuple()

Sort by

recency

|

1082 Discussions

|

  • + 0 comments

    Something I learned while solving this is that namedtuples have a ._make method that if the input string is in the same order as the namedtuple defintion string, it does the right thing:

    Record = namedtuple('Record', headers)
    :
    :
    read_input = input().split()
    read_record = Record._make(read_input)
    
  • + 0 comments

    Enter your code here. Read input from STDIN. Print output to STDOUT

    from collections import namedtuple n=input() student=namedtuple('student',input().split()) Students=[student(*input().split()) for _ in range(int(n))] print(round(sum(int(i.MARKS) for i in Students)/int(n),2))

  • + 0 comments

    Here is HackerRank Collections.namedtuples() in python solution - https://programmingoneonone.com/hackerrank-collections-namedtuple-solution-in-python.html

  • + 0 comments
    total = int(input())
    colums = input().split()
    info_ = list(input().split() for i in range(total))
    print(sum(list(map(int, list(map(lambda x: x[colums.index("MARKS")], info_)))))/total)
    

  • + 0 comments

    Collections.namedtuple() is a factory function in Python provided by the collections module that allows you to create simple, immutable classes for storing data — similar to a lightweight class, but with less boilerplate. Gold 365 Site