python check palindrome fast way

import sys

arg = sys.argv[1]
arg_length = len(sys.argv[1])

print("arg_length: ",arg_length)

def palindrome(arg, arg_length):
    for i in range(0,int(arg_length/2)): # for checking half string
        if arg[i] != arg[arg_length-i-1]:
            return False
    return True

print(palindrome(arg, arg_length))

Output:

[home@fedora ~]$ python3 palidrom.py 11211
arg_length:  5
True
[home@fedora ~]$ python3 palidrom.py noon
arg_length:  4
True
[home@fedora ~]$ python3 palidrom.py qwerty
arg_length:  6
False

python argument parser

consumer.py –server kafka:9092 –consumer_group group1 –topic test-topic1 –messages 100 –sleep 1

import sys
import time
import argparse

#consumer.py --server kafka:9092 --consumer_group group1 --topic test-topic1 --messages 100 --sleep 1

parser = argparse.ArgumentParser(description='Optional app description')
parser.add_argument('--server', type=str,
                    help='kafka server with port eg. kafka:9092.')

parser.add_argument('--consumer_group', type=str,
                    help='consumer_group name.')

parser.add_argument('--topic', type=str,
                    help='kafka topic name')

parser.add_argument('--messages', type=int,
                    help='number of message needs to be produced.')

parser.add_argument('--sleep', type=int,
                    help='sleep between message produced.')

args = parser.parse_args()

print("kafka arguments:")
print(args.kafka_server,args.consumer_group,args.topic,args.messages,args.sleep)

More – https://stackoverflow.com/questions/20063/whats-the-best-way-to-parse-command-line-arguments
https://docs.python.org/3/library/argparse.html