how does bitcoin prevent double-spending?

  bitcoin, pseudocode, python, security

can someone help me create a Pseudocode that shows how bitcoin prevents double-spending?
here is my code (with some help of :

This program is to prevent double-spending:

Person A and Person B go to a store with only one collective BTC to spend.
Person A buys a TV costing exactly 1 BTC.
Person B buys a motorcycle that also costs exactly 1 BTC.
blockchain = []
pool_of_unconfirmed_transactions = []

Both transactions go into a pool of unconfirmed transactions:
pool_of_unconfirmed_transactions.append(person A buys)
pool_of_unconfirmed_transactions.append(person B buys)

only the first transaction gets confirmations
and is verified by miners in the next block.
If person A buys == first buyer:
    person A's transaction == valid
    blockchain.append(person A's transaction)
    del mem_pool[person B's transaction]
    person B's transaction == valid
    del mem_pool[person A's transaction]

Whichever transaction gets the maximum number of network confirmations
(typically a minimum of six) will be included in the blockchain,
 while others are discarded.
Once confirmations and transactions are put on the blockchain
 they are time-stamped, rendering them irreversible and impossible to alter.

Is it ok?
any suggestion?

Source: Python Questions