Categories
Uncategorized

Duplicate files, different names – Python

The Problem We have a bunch of files, and some of them have the exact same contents but different names. Here’s what we do. We open the files, read the contents and get the md5. We then compare it and put it all in a dictionary. Example we have three files file1.txt, file2.txt and file3.txt, […]

Categories
Uncategorized

The **kwargs Function Argument – Python

**kwargs can be used for multiple arguments which don’t really have to be specified. All the information is then stored as a dictionary. So if we have a function like this and we run it like this we get this confirming it is a dictionary. We could also call each argument with a loop If […]

Categories
Uncategorized

Pajek to database – Python

This is how you read a pajek file and move it all to a database. This consists of three files, all in the same directory sample.txt – the pajek sample file pajek_rw.py – module that reads the pajek file g2db.py – which moves all the data to a database sample.txt This is what the pajek […]

Categories
Uncategorized

Colouring Clusters – Python

The Graph file The Python bit The Graph

Categories
Uncategorized

ncol2pajek – Python

I’ve just written a very short Python script that will change an ncol graph file to Pajek format. https://github.com/jose187/ncol2pajek Some info on how to use it The ncol File The format of the ncol file will normally be like this The node names should not have any spaces and they should be separated by a […]

Categories
Uncategorized

Counting Vowels in a String – Python

From this project. The Challenge Enter a string and the program counts the number of vowels in the text. For added complexity have it report a sum of each vowel found. The Logic Make a dictionary with the vowels as keys. Then loop through each letter in the string. If it’s a vowel, append it […]

Categories
Uncategorized

Check if Palindrome – Python

Another one of these challenges – this one is just too easy. The Challenge Checks if the string entered by the user is a palindrome. That is that it reads the same forwards as backwards like “racecar” The logic Since palindromes are the same whether they are spelled backwards or not, we can compare the […]

Categories
Uncategorized

Reverse a String – Python

As sad as it may sound, this is how I relax. EDIT: After reading this Reddit post, it seems the correct answer is Inspired by this reddit post, I’ve decided to have a go at some of them. So today I will have a go at reversing a string. The Challenge Enter a string and […]

Categories
Uncategorized

Names to MySQL db – Python

I have a very long list of files that are named like this…. [manufacturer]_[device].txt So this small script will take the names and put them on a database.

Categories
Uncategorized

Key words in directory – Python

This script will read all the text files in a directory and output a list of all the words and how many times they apear.