From 864be4754bf0c3df408c12634f62afd9d0c2c7d4 Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Sun, 23 Aug 2020 09:05:13 +0100 Subject: - Tidied file name of Python solutions by Lubos Kolouch. --- challenge-074/lubos-kolouch/python/ch-2.py | 43 ++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 challenge-074/lubos-kolouch/python/ch-2.py (limited to 'challenge-074/lubos-kolouch/python/ch-2.py') diff --git a/challenge-074/lubos-kolouch/python/ch-2.py b/challenge-074/lubos-kolouch/python/ch-2.py new file mode 100644 index 0000000000..da21ecc6fb --- /dev/null +++ b/challenge-074/lubos-kolouch/python/ch-2.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python +""" FNR character from Perl weekly challenge 074 task 2 """ + + +# =============================================================================== +# +# FILE: ch-_.py +# +# USAGE: ./ch_2.py +# +# DESCRIPTION: https://perlweeklychallenge.org/blog/perl-weekly-challenge-074/ +# +# TASK #2 › FNR Character +# +# AUTHOR: Lubos Kolouch +# VERSION: 1.0 +# CREATED: 08/22/2020 12:40:09 PM +# =============================================================================== + + +def get_fnr(in_str): + """ Find and return the FNR in the given string """ + + fnr_count = dict() + fnr_queue = list() + + result = '' + + for char in in_str: + fnr_count[char] = fnr_count.get(char, 0) + 1 + + if fnr_count[char] == 1: + fnr_queue.append(char) + else: + fnr_queue.remove(char) + + result += fnr_queue[-1] if fnr_queue else '#' + + return result + + +assert get_fnr('ababc') == 'abb#c' +assert get_fnr('xyzzyx') == 'xyzyx#' -- cgit