Mbare's Profile User Rating: -----

Reputation: 0 Apprentice
Active Posts:
17 (0.02 per day)
02-September 12
Profile Views:
Last Active:
User is offline Feb 27 2014 12:37 PM

Previous Fields

Dream Kudos:
Icon   Mbare has not set their status

Posts I've Made

  1. In Topic: Hard time understanding Class Wrappers

    Posted 15 Feb 2014

    the concept is simple:

    In your case UserDict is a wrapper class…
    this class mime dict built-in behavior and can extend it…
    You need wrappers class to add ad hoc functionality or change a standard functionality of a dict object (or others object like strings, etc..); for example :

    class My_dict(dict):
        def __setitem__(self, key, value):
            super().__setitem__(key, 'abracadabra')
    x = My_dict()
    print(type(x)) # -->  <class '__main__.My_dict'>  x == {}
    x['key'] = 31
    print(x)   # --> {'key': 'abracadabra'}

    now You have *cracked* setitem method of dict class :chris:/>

    look also at decorators
  2. In Topic: Python mini-challenge: "Lucky" numbers

    Posted 10 Feb 2014


    yes, I now noticed that you used += and not l + l then equivalent to extend ;)

    right! of course my list comp. works at O(n^2) isn’t a great improvement, but overall the func should have a *decent* efficency … however I have not tested it on large set…;) I’ll do that ;)

    ps. In these cases probably the better solution would be a structure like a *doubly linked list* --> O(1)-time update operations, including insertions and deletions at arbitrary positions within the list, and of course to work with *numpy-array* but all this probably falls outside the purpose of this post
  3. In Topic: Python mini-challenge: "Lucky" numbers

    Posted 10 Feb 2014

    HI good exercise for learn ;)/>
    Mekire's solution seems pretty good but we can improve efficiency with list comp. and hash table.
    And above all: Don’t use *list + list* ! use *extend* instead or better *chain* from itertools

    l = list(range(1, 100))
    def process_list(_list):
            _list  = _list[::2]
            _index = 1
            while _index < len(_list):
                _step   = _list[_index]
                _avoid_indx = {(i - 1): None for i in range(0, len(_list), _step)}  # Hash table search items in O(1)
                _list   = [i for i in _list if _list.index(i) not in _avoid_indx]
                _index += 1
            return _list

    now only for *didactics* purpose we know that Python’s list class relies on an algorithmic sleight : dynamic array. very efficient but not for all.(not for real time process for example)
    The first key to providing the semantics of a dynamic array is that a list instance
    maintains an underlying array that frequently has greater capacity than the current length
    of the list. --> Python’s implementation of the append method shows amortized constant-time behavior (otherwise it would work in linear time)

    finally parsing item's list works in O(n) linear time, instead hash table works in O(1).
  4. In Topic: It tells me i haven't defined get_min?

    Posted 6 Jan 2014

    View PostJorgee, on 05 January 2014 - 04:39 PM, said:

    Don't worry guys! I fixed it :3
    def hotel_cost(nights):
         bill = hotel_cost(5)
         return (nights) * 140
    def get_min(balance,rate):
        return min.bill

    this code is need to learn programming basics first(for example: recursions)
  5. In Topic: time complexity in while loop

    Posted 3 Jan 2014

    HI and thanks for answer.
    ok this is not a sort function for a classic *dynamic array-based sequence* , like list class in Python...
    but it refer positional list class based on a *double linked list*... similiar to Deque in python core lib, but in some aspects more efficient.
    it works with nodes, without indexing ;
    ps. for each iteration --> element(not position value) after 'marker' becomes pivot...etc..

    however also i think so...O(n^2)

My Information

Member Title:
New D.I.C Head
Age Unknown
Birthday Unknown

Contact Information



Mbare hasn't added any friends yet.


Mbare has no profile comments yet. Why not say hello?