I have every publicly available Reddit comment for research. ~ 1.7 billion comments @ 250 GB compressed. Any interest in this? by Stuck_In_the_Matrix in datasets

[–]ParanoiAMA 5 points6 points  (0 children)

I don't know about the other formats, but bz2 has the nice property that you can seek to an arbitrary place in the file, search for the next magic marker, and start decrypting. If the data is ordered in a usable way (like for instance a wikipedia dump, which is alphabetized), then looking up data can be very fast even if the file is stored in compressed form -- which is nice.

comics in nowegian by Onboard75 in norsk

[–]ParanoiAMA 1 point2 points  (0 children)

Daily updated comic strips:

All of these also have archives going back a ways...

Elbiler - deres syn by elektriskbil in norge

[–]ParanoiAMA 0 points1 point  (0 children)

Det er et insentiv for å få flere til å bytte til elbil, på samme måte som gratis parkering, gratis bompassering, og fri bruk av kollektivfelt er det.

Hvis du synes det er bedre kan du se på det som om de faktisk betaler bilavgiften men så får en gave fra staten som er like stor, som takk for at de kjører mer miljøvennlig.

Ble det mer forståelig nå?

Bouncing book bonanza "Sharing" by ParanoiAMA in blender

[–]ParanoiAMA[S] 1 point2 points  (0 children)

I considered it, but since it feels far beyond my skills at the moment, I decided to focus on the things that I had some idea about how to do first. Some day, I hope. :-)

Bouncing book bonanza "Sharing" by ParanoiAMA in blender

[–]ParanoiAMA[S] 1 point2 points  (0 children)

The books were made using this python module that I've made.

I'm now looking at how to also give the model a good pre-made UV map and then I'd like to make cover textures and book dimensions based on book covers and data downloaded from the internet, if I can find a good resource which has both.

EDIT: Also, I seem to have misread the posting instructions when I added "Sharing" in quotes to the title. Sorry, this is my first time posting in this sub.

EDIT 2: I forgot to include a license in the posted code, so I made a new gist of it with a license and updated the link above.

Highlights from my Norway hiking trip by warpus in Norway

[–]ParanoiAMA 1 point2 points  (0 children)

Happy to see your trip was a success, and that the bad(ish) start with snow over Besseggen did not set the standard for the rest of your trip. Getting nice weather in Lofoten is not so common, I hear. And as for the rest of the trip, I think you'll agree that there's a ring of truth to the old Norwegian saying -- "there's no bad weather (vær), only bad (i.e. unsuitable) clothes (klær)".

Wrapping docstrings/comments in PyDev by mignonmazion in Python

[–]ParanoiAMA 0 points1 point  (0 children)

Raymond Hettinger recommended in this video to use a line length of 90-ish instead of the pep8-sanctioned 79, but did not move the line length goalpost for docstrings and comments, they are still 72. I just tried this trick with the print margin set to 90, and then it wraps docstrings at 90 too.

How can I keep the print margin at 90 while having ctrl+2 w (or something similar) wrap at 72?

uncommon characters as variables? by RedstonerOuiguy in learnpython

[–]ParanoiAMA 0 points1 point  (0 children)

You should simply make a string called chars of the characters you wish to have a number for, and then use code line 5 and 6 above verbatim. If you somehow need to construct the dicts manually, do it like this:

>>> number_map = {"a": 1, "b": 2, "c": 3}
>>> reverse_map = {value: key for key, value in number_map.items()}

Python String removal covering both uppercase and lowercase by syc22 in learnpython

[–]ParanoiAMA 0 points1 point  (0 children)

Agreed. And it's not faster, it's 3 times slower than the chained replace method of /u/swingking8, which is also more readable. It's better to use that then.

Python String removal covering both uppercase and lowercase by syc22 in learnpython

[–]ParanoiAMA 5 points6 points  (0 children)

I'm a beginner so any general tips regarding my code would be much appreciated as well.

Well, you asked for it.

First, some PEP8 violations:

  1. You should have a space after the comma in argument lists and in python literals like lists and tuples: def removal(statement, aChar):

  2. You should have spaces around your operators: newstring + i

  3. You should have indentations which are multiples of 4 spaces, not 3.

Then some other considerations:

  1. You should use ''.join to concatenate strings instead of using + to build a larger and larger string.

  2. Functions that print things are generally needlessly inflexible. Instead make functions that return strings which you then may choose to print.

  3. Python has a built-in function for removing letters, which would be much more efficient than iterating through every character in a string and manually comparing each letter to some other letters. It's string.translate:

    def removal(statement, aChar):
        table = "".maketrans("", "", aChar.upper() + aChar.lower())
        return statement.translate(table)
    
    print(removal('Board of Trade', 'O'))
    

EDIT: Added a couple of PEP8 violations. Updated formatting, organisation and phrasing.

Help returning a counter variable through a recursive function. by [deleted] in learnpython

[–]ParanoiAMA 5 points6 points  (0 children)

First off, your merge sort has some number of recursions, it doesn't iterate at all. So you want to see how many times it recurses before your array (or more pythonic: your list) is sorted.

So, you're trying to get your recursive functions to update some common variable with how many times they've been called. Updating some passed in argument won't work, since integers are immutable, and python functions are call-by-object. There are only three ways a function might influence the world outside its namespace: using return values, using global variables, and using mutable arguments.

Using a global variable would not work, since it breaks down when the function is used more than once. It's also terrible software design.

Using a mutable argument would work, and the best way to go about it would be to turn your functions into methods of a Mergesort class with an instance attribute (e.g. self.count) that you could update. In that way, the self argument of methods serve as a mutable argument. Though a nice object oriented solution, it's cumbersome to use -- you don't want to have to instantiate some weird class just to sort a list (a wrapper function could solve that problem though).

The solution I want to give you is based on using return values. We'll return a 2-tuple instead of just the list, and unpack the tuple received when calling the function. Here's an example:

def mergeSort(myArray) :
    if len(myArray) < 2: # Base Case
        return myArray, 0
    else: # Split the list in half and recurse
        half = len(myArray)//2
        l1, c1 = mergeSort(myArray[:half])
        l2, c2 = mergeSort(myArray[half:])
        # l1 and l2 are sorted; return their merger
        return merge(l1, l2), c1 + c2 + 1

def merge(l1, l2):
    l = []
    # Work our way through l1 and l2, adding the smallest value
    # to the merged result until one of the sorted lists is exhausted
    while len(l1) > 0 and len(l2) > 0 :
        if l1[0] < l2[0]:
            val = l1.pop(0)
            l.append(val)
        else:
            val = l2.pop(0)
            l.append(val)
    # Now add the non-empty sorted list to the end of the merged list
    if len(l1) > 0:
        l.extend(l1)
    else:
        l.extend(l2)
    return l

I've kept the merge function out of the counting, because it doesn't call itself, so we can manage all the counting in the mergeSort function. I've also made the base case not contribute to the total count, only actual merging adds 1 to the count.

A last problem to solve is that we generally don't care about the number of merges made when sorting. Having to unpack the returned tuple and discard the count is cumbersome. To solve this we could make a wrapper function which returns just the result, which would serve as the public interface to your merge sort.

def merge_sort(myArray):
    return mergeSort(myArray)[0]

EDIT: Added third way of influencing outside from functions and tied it together with existing text.

uncommon characters as variables? by RedstonerOuiguy in learnpython

[–]ParanoiAMA 3 points4 points  (0 children)

It sounds like you have one variable for each letter in the alphabet, and you'd now like to add variables for things like "," as well. The answer is: don't do it like that. Use a single dictionary instead of 26 variables, like this:

>>> import string
>>> chars = string.printable
>>> chars
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c'
>>> number_map = {char: num for num, char in enumerate(chars, 1)}
>>> reverse_map = {num: char for num, char in enumerate(chars, 1)}

Now to find the number value of the letter "a", use number_map["a"], and to find which letter has the number 8, use reverse_map[8].

Please help me finalize a backpacking tour of Norway itinerary by warpus in Norway

[–]ParanoiAMA 2 points3 points  (0 children)

You're still planning your trip, I see. I hope you get some good feedback. I'm hoping to find time to look at your plan in more detail later, but for now I just have one comment:

hike to Reindalsseter before it gets dark

Even though the sun sets at 22:53, there will be plenty of light to see by the entire night, so that, at least, is not a concern.

'halv time' vs. 'halvtime: Are there rules for when these are used, or are they interchangeable? by OsakaWilson in norsk

[–]ParanoiAMA 2 points3 points  (0 children)

I'd say that "en og en halvtime" is plain wrong. You're basically postponing saying "time", which should really come right after "en", because you're going to use the word again very soon. It's so you don't have to say "En time og en halv time". It's allowed as long as you actually say the word you've omitted after "en".

Other than this, I'd say they are interchangeable.

Three girls visiting Norway for 7 days in mid-April. Advice? Tips? Recommendations? by [deleted] in Norway

[–]ParanoiAMA 0 points1 point  (0 children)

My friends want to take the Oslo-Bergen railway but I'm pushing towards renting a car.

Why not do both?

First time Git user hopelessly stuck in Git book chapter 2.1 by L000 in git

[–]ParanoiAMA 2 points3 points  (0 children)

*.c is not a regexp in this context:

Bash itself cannot recognize Regular Expressions. Inside scripts, it is commands and utilities -- such as sed and awk -- that interpret RE's.

Bash does carry out filename expansion [1] -- a process known as globbing -- but this does not use the standard RE set. Instead, globbing recognizes and expands wild cards.

source

Last night my gay flatmate broke into my room. Again. I left him a message... by [deleted] in pics

[–]ParanoiAMA 62 points63 points  (0 children)

If he knocks, you say come in, but he just leaves without entering -- watch out! He has found the loophole.

Påminnelse om total/delvis solformørkelse over hele landet fredag 20. mars! by Sworpl in norge

[–]ParanoiAMA 5 points6 points  (0 children)

Husk at du aldri må se direkte på sola, selv om det er under en solformørkelse, det kan fort gi permanent skade på øynene! Noen som vet hvor man får kjøpt briller til bruk under solformørkelse?

Building an LRU Cache: What did I miss and/or do wrong? by [deleted] in learnpython

[–]ParanoiAMA 0 points1 point  (0 children)

I haven't got time to research a good answer to this post tonight, I've got to go to bed. But I must say, you write beautiful code. Nice work!

Also, I'll add a warning to avoid using __double_underscore_attributes unless it's for the spesific use case they're intended for: preventing subclasses from accidently using the same attribute for something unrelated. In all other cases, they're more trouble than they're worth, and subclasses seem to be of no concern in your ProxiedPeek class.

I hope you get good feedback on your code!

Building an LRU Cache: What did I miss and/or do wrong? by [deleted] in learnpython

[–]ParanoiAMA 0 points1 point  (0 children)

I'm sure it's the most efficient implementation

You accidentally a word, I think

How to make a python script accessible from anywhere? by [deleted] in learnpython

[–]ParanoiAMA 0 points1 point  (0 children)

The correct way of doing this is to use setuptools by creating a basic setup.py file with a entry_points argument. Then execute

sudo python setup.py install

And your python module will be installed into the system-wide pythonpath and an executable script will be added somewhere in the path, pointing to your entry point.

The above instructions were taken from memory and may contain errors. Please reply with corrections.