Skip to content

Tag: python

Find matching values in a list of lists

I’m trying to iterate over a list of lists in python 2.7.5 and return those where the first value is found in a second list, something like this: So I would want list3 to contain [[‘aa’,1,3,7],[‘bc’, 3, 4, 4]] but instead I just get the whole of list2. Answer Try a more simple ap…

Spirograph Turtle Python

How can I play with a turtle and how can I use a turtle? I have trouble getting the thing to work as in the picture shown below (ignore the colors). I am trying to make that kind of shape. Here is the coding I have done so far. Answer Try changing your t_iterating function to this:

Skyscraper puzzle algorithm

I’m writing an algorithm to solve skyscrapers puzzles: Skyscraper puzzles combine the row and column constraints of Sudoku with external clue values that re-imagine each row or column of numbers as a road full of skyscrapers of varying height. Higher numbers represent higher buildings. To solve a Skyscr…

Remove very last character in file

After looking all over the Internet, I’ve come to this. Let’s say I have already made a text file that reads: Hello World Well, I want to remove the very last character (in this case d) from this text file. So now the text file should look like this: Hello Worl But I have no idea how to do this.

Django Simple Captcha image size

How can I change captcha image size and text padding in image? I read official docs and havn’t found any of those. Answer I have never used this app, but I’ve found in code something: So if you call captch_image with additional paramater scale, you can change the size. If you use urls for this app…

Random word generator- Python

So i’m basically working on a project where the computer takes a word from a list of words and jumbles it up for the user. there’s only one problem: I don’t want to keep having to write tons of words in the list, so i’m wondering if there’s a way to import a ton of random words s…

Decorating a class to monitor attribute changes

I want to have classes that automatically send notifications to subscribers whenever one of their attributes change. So if I would write this code: The output would be: My question is how to implement the ChangeMonitor decorator class. In the above example I assume it will print a line indicating the changes …