I'll be 18 when the next elections are coming up. Who should I choose to get free stuff?

Nobody. The bottom line is: nothing is free. You will be one of those American taxpayers and pay for the rest of your life for the college education and college education of everyone else. Due to the interest of irresponsible politicians in Washington, both Republicans and Democrats, public debt continues to rise sharply.

Beginners – Fantasy Game Inventory – Automate the boring stuff with Python

Below is my code for the Fantasy Game Inventory problem in Chapter 5 of Automate the boring stuff with Python. Can I do anything to make it cleaner or more efficient?

The code begins with a dictionary "inv" containing the player's current inventory and a list "dragon_loot" containing the items of the dead dragon. The goal of the code is to combine the list with the dictionary while increasing the number of duplicate elements.

As a note, I use the startup list from the previous question, simply because it seems impossible to kill a dragon without owning a weapon 🙂

You create a fantasy video game. The data structure for modeling the player's inventory is a dictionary in which the keys are string values ​​describing the item in the inventory, and the value is an integer value indicating how many items the player has. For example, the dictionary value means {# rope #: 1, F torch #: 6, Gold gold coin #: 42, Dol dagger #: 1, & 39; # 39; Arrow #: 12} that the player has 1 rope, 6 torches and 42 gold coins and so on.

Fantasy Game Inventory dictionary feature list

Imagine the spoils of a defeated dragon are represented as a list of strings:

dragonLoot = ('gold coin', 'dagger', 'gold coin', 'gold coin', 'ruby')

Write a function named addToInventory (inventory, addedItems), where the inventory parameter is a dictionary that represents the inventory of the player (as in the previous project), and the addedItems parameter is a list like dragonLoot. The addToInventory () function should return a dictionary that represents the updated inventory. Note that the added element list may contain multiple elements of the same element. Your code might look something like this:

def addToInventory(inventory, addedItems):
    # your code goes here

inv = {'gold coin': 42, 'rope': 1}
dragonLoot = ('gold coin', 'dagger', 'gold coin', 'gold coin', 'ruby')
inv = addToInventory(inv, dragonLoot)
displayInventory(inv)

The output of the following code is:

Inventory:
1 rope
6 torch
45 gold coin
2 dagger
12 arrow
1 ruby

Total number of items: 67

Thank you in advance. I've learned a lot from the comments I received on my previous questions!

from collections import Counter

# players current inventory before killing dragon
inv = {'rope': 1, 'torch': 6, 'gold coin': 42, 'dagger': 1, 'arrow': 12}

# items from the slain dragon
dragon_loot = ('gold coin', 'dagger', 'gold coin', 'gold coin', 'ruby')

# this function prints the players inventory in a list and reports the total items
def display_inventory(inventory):
    print("Inventory:")
    item_total = 0
    for k, v in inventory.items():
        print(str(v) + " " + str(k))
        item_total = item_total + int(v)
    print("nTotal number of items: " + str(item_total))

# this function adds the dragon's stuff to the players inventory
def add_to_inventory(inventory, added_items):
        added_items_dict ={i:added_items.count(i) for i in added_items}
        inv = Counter(inventory) + Counter(added_items_dict)
        return inv

inv = add_to_inventory(inv, dragon_loot)
display_inventory(inv)

SQL Server Behavior of the STUFF function on empty strings

When answering another question (to SO), I came across an unexpected behavior with the function STUFF.

SELECT STUFF
(
    'a', -- character expression
    1,  -- start
    1,  -- length
    'z' -- replaceWith_expression
)

returns NULLwhile I would expect it to be & # 39; z & # 39; returns.

The STUFF function inserts a string into another string. It deletes a specified character length in the first string at the start position, and then inserts the second string at the start position into the first string.

syntax

STUFF ( character_expression , start , length , replaceWith_expression )

Remarks

If the start position or length is negative, or if the start position is greater than the length of the first string, a null string is returned. If the start position is 0, a null value is returned. If the length to be deleted is longer than the first string, it is deleted up to the first character in the first string.

An error is thrown if the resulting value is greater than the maximum supported by the return type.

According to the documentation, there are a number of reasons why a NULL string is returned:

  • If Beginning is longer than the first zeichen_ausdruck
  • If Beginning is negative or 0
  • If length is negative

[ Politics ] Open question: Have you read the new book by Michelle Malkin (open boarders inc)? It outlines All the criminal stuff the DNC has set up to support it.

(Politics) Open question: Have you read the new book by Michelle Malkin (open boarders inc)? It outlines
All the criminal stuff the DNC has set up to support it. (tagsToTranslate) Yahoo (t) answered (t) questions (t) Politics & Government (t) Politics

OS stuff | Forum Promotion – Best Webmaster, Admin and Internet Marketing Forum

Site Name: OS stuff
URL: http://os-stuff.boards.net/
type: Forum

Info:
OS stuff is a Forum that is dedicated discussions from operating systems, You can talk about everything operating systems either be it discussions over MS Windows. Mac OS X. GNU / Linux or anyone else OS!

I always add boards for others operating systems, If you would like to join us, please contact us.

Python – Automate the boring stuff: Character Picture Grid

How can I improve this code?

def print_rotate_grid (a_grid):
Lines = length (grid)
cols = len (grid[0])

for col in range (cols):
for row in range (rows):
print (a_grid[row][col], end = & # 39; & # 39;
Print (& # 39;)



if __name__ == & # 39; __ main __ & # 39 ;:
grid = [['.', '.', '.', '.', '.', '.'].
            ['.', '0', '0', '.', '.', '.'].
            ['0', '0', '0', '0', '.', '.'].
            ['0', '0', '0', '0', '0', '.'].
            ['.', '0', '0', '0', '0', '0'].
            ['0', '0', '0', '0', '0', '.'].
            ['0', '0', '0', '0', '.', '.'].
            ['.', '0', '0', '.', '.', '.'].
            ['.', '.', '.', '.', '.', '.'],]print_rotate_grid (grid)

Python – Regex version of strip () – Ch. 7 Automate the boring stuff

Here is an exercise – Regex version of Strip () $ – $

Write a function that accepts a string and does the same thing as the string
Strip () String method. If no arguments other than those are passed
To remove a string, spaces are removed from the list
Beginning and end of the string. Otherwise, the characters are specified
in the second argument, the function is removed from the
String.

I wrote the following code. Is there a better way to write it? Every feedback is appreciated.

Import again

def regex_strip (s, chars = None):

If characters == None:
strip_left = re.compile (r & # 39; ^  s * & # 39;
strip_right = re.compile (r & # 39;  s * $ & # 39;

s = re (strip_left, "", s)
s = re (strip_right, "", s)
otherwise:
strip_left = re.compile (r & # 39; ^[' + re.escape(chars) + r']* & # 39;)
strip_right = re.compile (r & # 39;[' + re.escape(chars) + r']* $ & # 39;)
s = re (strip_left, "", s)
s = re (strip_right, "", s)
returns

Here is an example output –

s = & # 39 ;. * alphabetatheta * 4453 + - & # 39;
print (regex_strip (s, & # 39; + - * & # 39;))

>>> alphabetatheta * 4453   

simplicial stuff – techniques for calculating homotopy pullbacks

I am related to simple quantities. I have a square chart that I want to show as a homotopy pullback. What I can understand is that it is a step backwards to a few equivalencies at the center of my thinking, and I want to make this a true statement.

So let it go $ p: X to Z, q: Y to Z $ Map of ssets and $ f: P to X, g: P to Y $ another two cards from the alleged homotopy pullback. Suppose that for everyone $ x in X $that induced card on fibers $ P to Y $ is an equivalence. In addition, you can also assume $ p, q $ are Kan fibrations. Is it true that $ P $ is the homotopy pullback of the graph?

Related Question: Can homotopy retractions of spaces be checked for fibers?

The difference is that they are not spaces (= Kan complexes) but general simplicial sets. I also want to use real and no homotopic fibers.

Reference: http://palmer.wellesley.edu/~ivolic/pdf/Papers/CubicalHomotopyTheory.pdf

Proposition 3.3.18. Many Thanks!

Python – Comma Code – Ch. 4 Automate the boring stuff

Your code is well built, but could be made much shorter by using it .Format() Function.

str.format () is one of the string formatting methods in Python 3, the
Enables multiple substitutions and value formatting. This method leaves
We combine elements within a string by positional formatting.

Your code can therefore be made shorter and more concise in this way. This is how your code might look like:

def list_concatenator (your_list):
if not your_list:
return "Your list is empty!"
elif len (your_list) == 1:
return str (your_list[0])
elif len (your_list) == 2:
Return {0} and {1}. format (your_list[0], your list[1])
otherwise:
body = "," .join (map (str, your_list[:-1]))
Give & # 39; {0} and {1} & # 39; back. format (body, your_list[-1])

I have used {0} and {1} This allows positional arguments to be placed in the order in which you want them. This is not necessary.

The .Format() Instructions also take care of the Oxford comma, with lists containing two Elements have no commas but lists with more than Two elements are separated by commas.

Here are some example editions –

#your_list = ['item1', 'item2', 3, 'item4', 'item5', 'item6', 7, 'item8', 9]

#print (list_concatenator (['item1', 'item2', 3, 'item4', 'item5', 'item6', 7, 'item8', 9]))

>>> Article 1, Articles 2, 3, Article 4, Article 5, Articles 6, 7, Articles 8 and 9

#print (list_concatenator (['item1', 'item2', 3]))

>>> item1, item2 and 3

#print (list_concatenator (['item1', 3]))

>>> points 1 and 3

#print (list_concatenator (['item1']))

>>> item1

#print (list_concatenator ([]))

>>> Your list is empty!

Overall, I think formatting was the main problem in your code.

Hope that helps!