Private Proxies – Buy Cheap Private Elite USA Proxy + 50% Discount!Private Proxies – Buy Cheap Private Elite USA Proxy + 50% Discount!Private Proxies – Buy Cheap Private Elite USA Proxy + 50% Discount!Private Proxies – Buy Cheap Private Elite USA Proxy + 50% Discount!
    0
  •   was successfully added to your cart.
  • Home
  • Buy proxies
  • Extra features
  • Help
  • Contact
  • Login
  • 50% OFF
    BUY NOW!
    50
    PROXIES
    $19
    --------------------
    BUY NOW!
    BUY NOW!
    BUY NOW!
    BUY NOW!
    BUY NOW!
    $29
    $49
    $109
    $179
    $299
    --------------------
    --------------------
    --------------------
    --------------------
    --------------------
    PROXIES
    PROXIES
    PROXIES
    PROXIES
    PROXIES
    100
    200
    500
    1,000
    2,000
    TOP SELLER
    BEST VALUE
    For All Private Proxies!

get names from names.txt get transactions from transactions.txt

display who owe what like so

The output of the program should print the following lines:

Alice pays $ xx.xx to David.

Bob pays $ xx.xx to Claire.

And so on.

names.txt

Alice Bob Claire David 

transtions.txt

Bob paid $  55.90 for petrol. Bob paid $  70 for house-cleaning. Bob paid $  85.60 for lunch. Claire paid $  100.10 for phone bill. Claire paid $  103.45 for dinner. Claire paid $  30.80 for snacks. David paid $  170.80 for groceries. David paid $  33.40 for breakfast. David paid $  63.50 for utilities. 

my code works and get the right result, just wondering if there is a cleaner way.

The code creates payment object, adds people, then adds payments, then gets liabilities.

Let me know what y’all think.

import re from decimal import Decimal  def filer(file):     f = open(file, 'r')     lines = []     for line in f.readlines():         lines.append(line.strip())     return lines  def parse_lines(lines, **kwargs):     compilers = kwargs.get('keys', ['money', 'name', 'bill'])     parses = []     for line in lines:         l1 = Parser(line, keys=compilers)         parses.append(l1.get_dict())     return parses   class Parser(object):     patterns    = {'name_pattern':'^([\w\-]+)','money_pattern':'(\d+.?\d*)','bill_pattern':"[\w'-]+\.$  "}     keys        = ['money', 'name', 'bill']      def __init__(self, line, **kwargs):         if 'patterns' in kwargs:             self.patterns.update(kwargs.get('patterns'))             del kwargs['patterns']          self.__dict__.update(kwargs)          for key in self.keys:             key_str = key+'_pattern'             parser  = re.compile(self.patterns[key_str])             value   = parser.search(line)             setattr(self, key, value.group(0))      def get_dict(self):         rtn = {}         for key in self.keys:             rtn[key] = getattr(self, key)         return rtn  class Payments(object):      def __init__(self, **kwargs):         self.people         = {}         self.formatter  = "{from} ​pays​ {currency}{amount} ​to​ {to}."         self.currency   = '$  '         self.__dict__.update(kwargs)      def add_person(self, person):         self.people[str(person.name)] = person      def add_payment(self, payment):         person = self.people[payment['name']]         person.add_to(payment)      def get_liabilities(self):         liabilities     = []         for name, person in self.people.items():             person.set_share(len(self.people.items()))          for name, person in self.people.items():             """gets share & sets it against each person in the group"""             person.set_liability(self.people, self.currency)             liabilities += person.liabilities          return liabilities      def print_liabilities(self):         liabilities = []         for liability in self.get_liabilities():             liabilities.append(self.formatter.format(**liability))         return liabilities  class Person(object):     def __init__(self, **kwargs):         self.name   = ""         self.items  = []         self.paid   = 0         self.share  = 0         self.liabilities = []         self.__dict__.update(kwargs)      def add_to(self, payment):         """ payment must have keys: 'name', 'money'"""         if payment['name'] == self.name:             self.items.append(payment)      def _get_paid(self):         balance = 0         for item in self.items:             amount  = Decimal(item['money'],2)             balance += amount         return Decimal(balance, 2)      def set_share(self, total_people):         """total amount paid is divided by the number of          people to get the liabilities of each person"""         self.paid   = self._get_paid()         self.share  = round(self.paid/Decimal(total_people), 2)      def _set_extras(self, liability, keys):         """sets extra properties"""         for key in keys:             if hasattr(self, key):                 liab_dict[key] = getattr(self, key)      def set_liability(self, people, currency):         """if owed is share is greater than owed, name needs to pay this"""         for name, person in people.items():             if self.name != name:                 """if owed is greater than what I have paid then add to liabilities"""                 diff = self.share - person.share                 if diff < 0:                     liab_dict = {'from':self.name,'to': name,'amount':-diff, 'currency':currency }                     self.liabilities.append(liab_dict)  class PaymentBuilder(object):     people  = []     def __init__(self, **kwargs):         transactions    = kwargs.get('transaction_file','./transactions.txt')         names           = kwargs.get('names_file','./names.txt')         self.payments   = Payments()         self.trans      = parse_lines(filer(transactions))         self.names      = filer(names)          for name in self.names:             self.payments.add_person(Person(name=name))         for tran in self.trans:             self.payments.add_payment(tran)      def liabilities(self):         return [ liability for liability in self.payments.print_liabilities()] 

✓ Extra quality

ExtraProxies brings the best proxy quality for you with our private and reliable proxies

✓ Extra anonymity

Top level of anonymity and 100% safe proxies – this is what you get with every proxy package

✓ Extra speed

1,ooo mb/s proxy servers speed – we are way better than others – just enjoy our proxies!

50 proxies

$19/month

50% DISCOUNT!
$0.38 per proxy
✓ Private
✓ Elite
✓ Anonymous
Buy now

100 proxies

$29/month

50% DISCOUNT!
$0.29 per proxy
✓ Private
✓ Elite
✓ Anonymous
Buy now

200 proxies

$49/month

50% DISCOUNT!
$0.25 per proxy
✓ Private
✓ Elite
✓ Anonymous
Buy now

500 proxies

$109/month

50% DISCOUNT!
$0.22 per proxy
✓ Private
✓ Elite
✓ Anonymous
Buy now

1,000 proxies

$179/month

50% DISCOUNT!
$0.18 per proxy
✓ Private
✓ Elite
✓ Anonymous
Buy now

2,000 proxies

$299/month

50% DISCOUNT!
$0.15 per proxy
✓ Private
✓ Elite
✓ Anonymous
Buy now

USA proxy location

We offer premium quality USA private proxies – the most essential proxies you can ever want from USA

100% anonymous

Our proxies have TOP level of anonymity + Elite quality, so you are always safe and secure with your proxies

Unlimited bandwidth

Use your proxies as much as you want – we have no limits for data transfer and bandwidth, unlimited usage!

Superfast speed

Superb fast proxy servers with 1,000 mb/s speed – sit back and enjoy your lightning fast private proxies!

99,9% servers uptime

Alive and working proxies all the time – we are taking care of our servers so you can use them without any problems

No usage restrictions

You have freedom to use your proxies with every software, browser or website you want without restrictions

Perfect for SEO

We are 100% friendly with all SEO tasks as well as internet marketing – feel the power with our proxies

Big discounts

Buy more proxies and get better price – we offer various proxy packages with great deals and discounts

Premium support

We are working 24/7 to bring the best proxy experience for you – we are glad to help and assist you!

Satisfaction guarantee

24/7 premium support, free proxy activation and 100% safe payments! Best reliability private proxies for your needs!

Best Proxy Packs

  • 2,000 Private Proxies $600.00 $299.00 / month
  • 1,000 Private Proxies $360.00 $179.00 / month

Quick Links

  • More information
  • Contact us
  • Privacy Policy
  • Terms and Conditions

Like And Follow Us


Copyright ExtraProxies.com | All Rights Reserved.
  • Checkout
  • Contact
  • Help
  • Home
  • My Account
  • My Cart
  • News
  • Privacy Policy
  • Proxy features
  • Proxy packs
  • Terms and Conditions
Private Proxies – Buy Cheap Private Elite USA Proxy + 50% Discount!
    0 items