Skip to main content
added 22 characters in body
Source Link
Ludisposed
  • 11.8k
  • 2
  • 41
  • 91

I think this code is very straightforward and easy to read. Good job!

Some nitpicks are,

You have a few PEP8 violations none all that concerning.

  1. Should add a second white line between imports and your functions
  2. Line too long, at your print statement
  3. Continuation line under-indented for visual indent
  4. printf style formatting is recommended against

Code suggestions

I would use a namedtuple instead of a dictionary, since it is much cleaner looking and easier to use. When to use a namedtuple!

Using the above suggestions and adhering PEP8 I get the following.

from re import split
from collections import namedtuple


def get_messages():
    Message = namedtuple('Message', 'idx num length message')
    messages = []

    while True:
        try:
            recv = split(r'\s+', input())
            yield messages.append(Message(recv[0], recv[1], recv[2], ' '.join(recv[3:])))
        except EOFError:
            breakreturn messages


def mainprint_messages(messages):
    packetsfor =message []in messages:
    for packet in get_messages():
 print("{}  {} {} {}"
   packets.append(packet)

    packets = sorted(packets, key=lambda x: .format(xmessage.idx, xmessage.num, message.length, message.message))
    for packet in packets:
       
def printmain("{}):  {} {} {}"
       messages = sorted(get_messages(), key=lambda x: .format(packetx.idx, packetx.num,))
 packet.length, packet.message)  print_messages(messages) 


if __name__ == '__main__':
    main()

I think this code is very straightforward and easy to read. Good job!

Some nitpicks are,

You have a few PEP8 violations none all that concerning.

  1. Should add a second white line between imports and your functions
  2. Line too long, at your print statement
  3. Continuation line under-indented for visual indent
  4. printf style formatting is recommended against

Code suggestions

I would use a namedtuple instead of a dictionary, since it is much cleaner looking and easier to use. When to use a namedtuple!

Using the above suggestions and adhering PEP8 I get the following.

from re import split
from collections import namedtuple


def get_messages():
    Message = namedtuple('Message', 'idx num length message')

    while True:
        try:
            recv = split(r'\s+', input())
            yield Message(recv[0], recv[1], recv[2], ' '.join(recv[3:]))
        except EOFError:
            break


def main():
    packets = []
    for packet in get_messages():
        packets.append(packet)

    packets = sorted(packets, key=lambda x: (x.idx, x.num))
    for packet in packets:
        print("{}  {} {} {}"
            .format(packet.idx, packet.num, packet.length, packet.message))

if __name__ == '__main__':
    main()

I think this code is very straightforward and easy to read. Good job!

Some nitpicks are,

You have a few PEP8 violations none all that concerning.

  1. Should add a second white line between imports and your functions
  2. Line too long, at your print statement
  3. Continuation line under-indented for visual indent
  4. printf style formatting is recommended against

Code suggestions

I would use a namedtuple instead of a dictionary, since it is much cleaner looking and easier to use. When to use a namedtuple!

Using the above suggestions and adhering PEP8 I get the following.

from re import split
from collections import namedtuple


def get_messages():
    Message = namedtuple('Message', 'idx num length message')
    messages = []

    while True:
        try:
            recv = split(r'\s+', input())
            messages.append(Message(recv[0], recv[1], recv[2], ' '.join(recv[3:])))
        except EOFError:
            return messages


def print_messages(messages):
    for message in messages:
        print("{}  {} {} {}"
            .format(message.idx, message.num, message.length, message.message))


def main():    
    messages = sorted(get_messages(), key=lambda x: (x.idx, x.num))
    print_messages(messages) 


if __name__ == '__main__':
    main()
Post Undeleted by Ludisposed
added 1095 characters in body
Source Link
Ludisposed
  • 11.8k
  • 2
  • 41
  • 91

I think this code is very straightforward and easy to read. Good job!

Some nitpicks are,

You have a few PEP8 violations none all that concerning.

  1. Should add a second white line between imports and your functions
  2. Line too long, at your print statement
  3. Continuation line under-indented for visual indent
  4. Some other concerns are your use of printf statements.style formatting is recommended against
  • You use Python3 so why not use the fancy f"a string {the_item}" prints
  • or even "a string {}".format(the_item) is better.

Code suggestions

I would use a namedtuple instead of a dictionary, since it is much cleaner looking and easier to use. When to use a namedtuple!

Using the above suggestions and adhering PEP8 I get the following.

from re import split
from collections import namedtuple


def get_messages():
    Message = namedtuple('Message', 'idx num length message')

    while True:
        try:
            recv = split(r'\s+', input())
            yield Message(recv[0], recv[1], recv[2], ' '.join(recv[3:]))
        except EOFError:
            break


def main():
    packets = []
    for packet in get_messages():
        packets.append(packet)

    packets = sorted(packets, key=lambda x: (x.idx, x.num))
    for packet in packets:
        print("{}  {} {} {}"
            .format(packet.idx, packet.num, packet.length, packet.message))

if __name__ == '__main__':
    main()

I think this code is very straightforward and easy to read. Good job!

Some nitpicks are,

You have a few PEP8 violations none all that concerning.

  1. Should add a second white line between imports and your functions
  2. Line too long, at your print statement
  3. Continuation line under-indented for visual indent
  4. Some other concerns are your use of printf statements.
  • You use Python3 so why not use the fancy f"a string {the_item}" prints
  • or even "a string {}".format(the_item) is better.

I think this code is very straightforward and easy to read. Good job!

Some nitpicks are,

You have a few PEP8 violations none all that concerning.

  1. Should add a second white line between imports and your functions
  2. Line too long, at your print statement
  3. Continuation line under-indented for visual indent
  4. printf style formatting is recommended against

Code suggestions

I would use a namedtuple instead of a dictionary, since it is much cleaner looking and easier to use. When to use a namedtuple!

Using the above suggestions and adhering PEP8 I get the following.

from re import split
from collections import namedtuple


def get_messages():
    Message = namedtuple('Message', 'idx num length message')

    while True:
        try:
            recv = split(r'\s+', input())
            yield Message(recv[0], recv[1], recv[2], ' '.join(recv[3:]))
        except EOFError:
            break


def main():
    packets = []
    for packet in get_messages():
        packets.append(packet)

    packets = sorted(packets, key=lambda x: (x.idx, x.num))
    for packet in packets:
        print("{}  {} {} {}"
            .format(packet.idx, packet.num, packet.length, packet.message))

if __name__ == '__main__':
    main()
Post Deleted by Ludisposed
Source Link
Ludisposed
  • 11.8k
  • 2
  • 41
  • 91

I think this code is very straightforward and easy to read. Good job!

Some nitpicks are,

You have a few PEP8 violations none all that concerning.

  1. Should add a second white line between imports and your functions
  2. Line too long, at your print statement
  3. Continuation line under-indented for visual indent
  4. Some other concerns are your use of printf statements.
  • You use Python3 so why not use the fancy f"a string {the_item}" prints
  • or even "a string {}".format(the_item) is better.