How to edit and add words sequentially in a list - Python

I don't know if this is possible as I'm a newbie to Python, but I wanted to create a list that has a sequential order to it. So I have two lists as follows: stock_list = ['MSFT', 'YHOO'] ret = [0, 1, 2, 3] returns = ["ret{}".format(*ret) for ret

access portions of np.array

I want to have quick access to np.array elements for example from indexes from 0-6 plus 10 to the end. So far I have tried: a[0:6,10:] or np.concatenate(a[0:6],a[10:]) both are giving me error, with the second one giving me:"TypeError: only integer s

Merge tuples if they have a common element

Consider the following list: tuple_list = [('c', 'e'), ('c', 'd'), ('a', 'b'), ('d', 'e')] How can I achieve this? new_tuple_list = [('c', 'e', 'd'), ('a', 'b')] I have tried: for tuple in tuple_list: for tup in tuple_list: if tuple[0] == tup[0]: new

Test environment with mocked REST API

Lets say I have a very simple web app which is presented as blue if the current president is a democrat and red if they are a republican. A REST API is used to get the current president, via the endpoint: /presidents/current which currently returns t

Unable to understand numpy array additions

I am sure that this is a very basic question. However, even after going through several tutorial pages and the official documentation, I am not able to understand the addition logic in numpy arrays. Consider the following for example: In [5]: a = np.

How to change a string in Unicode in Python 2?

I have a string like s1 = "\xed\xf3\xb4\x90". >>> x = u"\xed\xf3\xb4\x90" >>> print x íó´ How could I use s1 to print this? I have tried: s1= "\xed\xf3\xb4\x90" print unicode(s1) But I could not get íó´. How

is there a way to summarize an account?

This is my first post, and I will try to be as detailed as possible. I am recreating the game "Mastermind", but instead of colors, letters are used. The color "red" would be "R", "yellow" would be "Y", etc

Matrix basic help in python

n=input("r") m=input("c") l=range(m*n) for r in range(m): for c in range(n): l[r][c]=input(" enter no") for r in range(m): for c in range(n): print[r][c] print i thought of practicing matrix questions but when i ran my matrix

java getBytes () equivalent in python

I am a nebie to python. I have a java method which accepts a string, converts the string to a byte array and returns the byte array. The method looks like this. private static byte[] convert(String str) { byte[] byteArray = str.getBytes(); return byt

how to get the password of the database?

please help to get the user's password by username views.py: def qwe(request): if request.method == "POST" and request.is_ajax(): #username = request.POST.get('username', '') username ="admin" username_req = User.objects.filter(usernam

Why the code does not run after receiving the response

I'm running the code below and it takes the user to PayPal to make a payment and then returns them to the return_url as expected. However the code doesn't execute any further and it doesn't execute the payment. I have based my code on https://github.

Get nested dict objects using Jinja2 in Flask

for this dictionary with this Flask controller projects = { 'life-calc':{'url':'life-calc', 'title': 'Life Calculator'}, 'text-game':{'url':'text-game', 'title':'Text Adventure'}, 'fill-it-up':{'url':'fill-it-up', 'title':'Fill It Up'}, 'rock-paper-s

Choose / Remove Python on Mac and PYTHONPATH

I started to use a Mac after someone and I encountered problems with Numpy/Matplotlib version. It turned out that there are several Python installations there and things from different installations are imported (which don't work together). I have: 1

Remove the command of a button

b1=Button(bla bla bla,command=run_something) b1.configure (command='') I want to remove the 'command' from a button so that if pressed nothing happens how would I do this? note: I did not use the b1.bind(<"button-1">) no I cant change it t

Get all tags from taggit

How to get all the (unique) tags from django-taggit? I would like to display all the tags in a side bar. Currently I am able to get all the tags for a particular post, but now I need to get all the unique tags in the entire blog. code in models.py: f

Xls to csv converter

I am using win32.client in python for converting my .xlsx and .xls file into a .csv. When I execute this code it's giving an error. My code is: def convertXLS2CSV(aFile): '''converts a MS Excel file to csv w/ the same name in the same directory''' pr

Python list in a function in a class

I'm trying to print the list created by the functions in this class- what do I need to fix? I'm getting output from the terminal along the lines of [<__main__.Person instance at 0x1004a0320>,. class Person: def __init__(self,first,last,id,email): se

Make Python ignore .pyc files

Is there a way to make Python ignore any .pyc files that are present and always interpret all the code (including imported modules) directly? Google hasn't turned up any answers, so I suspect not, but it seemed worth asking just in case. (Why do I wa

Difference between Python Generators and Iterators

What is the difference between iterators and generators? Some examples for when you would use each case would be helpful.iterator is a more general concept: any object whose class has a next method (__next__ in Python 3) and an __iter__ method that d

templatetags does not refresh

I have two templatetags in my app which contain forms which show entries in db. When I alter data or add new entry to db, the forms show the old data. While in admin panel everything is correct (updated). When I restart the server (I mean manage.py r

Convert a string to pre-existing variable names

How do I convert a string to the variable name in Python? For example, if the program contains a object named self.post that contains a variable named, I want to do something like: somefunction("self.post.id") = |Value of self.post.id| As refere