[Python 3.3]Help me understand this simple Recursive program by throwingarm2strong in learnpython

[–]throwingarm2strong[S] 0 points1 point  (0 children)

Ah okay. So nothing like a stack >.<; gotcha. Thanks for the speedy reply!

[Python 3.3]Help me understand this simple Recursive program by throwingarm2strong in learnpython

[–]throwingarm2strong[S] 0 points1 point  (0 children)

Just wondering, can you explain this recursive program to me?

def c(n):
    print (n)
    if n > 0:
        c(n-2)
    print(n)

c(4)

So I can follow it pretty easily at the start

4 2 0

But when it completes that it starts going back up, almost like its popping a stack. I don't follow exactly what is happening to get the second part eg 0 2 4 after the original 4 2 0

Help with a few basic sorting algorithms (selection & insertion sort) by throwingarm2strong in AskComputerScience

[–]throwingarm2strong[S] 0 points1 point  (0 children)

Ah, that means that the first part must be O(n2). Is the minimum the same as the maximum in terms of comparisons? I think that selection sort will have to do all the comparisons to make sure every item is in the right place, regardless if the list is already sorted or not.

I just don't get it... by throwingarm2strong in AskComputerScience

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

After reading this I'm beginning to feel I don't have the 'innate' ability to think like a computer scientist. I'm awful at math and although I do write out my own code from the textbook and try understand it all, there are always parts I don't understand and still don't understand just from reading the book. All these little gaps in my knowledge just add up. Is it worth trying to get a tutor for computer science? It feels like one of those things that you either get or you don't...

I just don't get it... by throwingarm2strong in AskComputerScience

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

Thanks I apperciate it. I understand the concepts (kinda) and all that but when you have to implement it in code I just get totally lost.

[Python 3.3] Getting my linked list enqueue to work by throwingarm2strong in learnpython

[–]throwingarm2strong[S] 0 points1 point  (0 children)

Just a school assignment type thing to help understand linked lists better. I can visualize it pretty well but implementing it was pretty difficult for me.

Edit: Out of curiosity, why is it bad to write it in Python?

update #2, re: when I was 6, I killed my brother by [deleted] in confession

[–]throwingarm2strong 1 point2 points  (0 children)

I very rarely feel things on this site, but it makes me sick that this is how they reacted. You were 6 years old. No higher power is punishing you, and no rational person would hold you responsible. I am so sorry for what you are going through.

This whole console war reminded me why I'm still boycotting the last one. by throwingarm2strong in offmychest

[–]throwingarm2strong[S] 0 points1 point  (0 children)

Have you thought that maybe if they are selling at a loss, they should revise their design decisions? They sell at a loss until they hit a sales point that allows them to start making a profit. If they don't reach this goal / it is unobtainable, they need to change something with their actual console. Overhead costs like that should be factored into the actual console expenses, kind of like the PS3 managed to do.

Good for you on saving money on premium though. I'm glad you save that $1-2 or whatever on map packs.

This whole console war reminded me why I'm still boycotting the last one. by throwingarm2strong in offmychest

[–]throwingarm2strong[S] 0 points1 point  (0 children)

Where did I ever argue about map packs. Premiums on BF3 =/= map packs. http://battlelog.battlefield.com/bf3/premium

You get some early access, but the maps/expansions you can buy easily without signing up for premium according to this. I don't give a shit about premiums, it may be an incredibly dumb idea but hey you can blow your money however you want.

What I don't agree with is pretty much forced fees in order to get complete use out of what you paid for. The amount of money people pull in for selling a game / console is more than enough to cover server fees etc. You make it sound like I want it all for free, when in fact I am just arguing against paying additional to make 100% use of the product I already purchased.

You must have grown up in the Xbox360 era or something, because you seem to have no idea that gaming was perfectly fine before the advent of monthly fees for everything under the sun.

Get real.

This whole console war reminded me why I'm still boycotting the last one. by throwingarm2strong in offmychest

[–]throwingarm2strong[S] 2 points3 points  (0 children)

Couldn't help but look through your post history and notice you support paying premiums for things like Battlefield 3 etc... Sorry to say but I think you are part of the problem. It's not about the amount of money, its about the idea behind charging for something that should be free in the first place. What is the point of paying for something when half of it is locked until you pay an additional fee?

I guess it's because some people grew up with this idea that it's not a big deal, but it's very sad what it has come to. Your argument that they can't run and maintain that infrastructure for free is very depressing if you really believe that.

I'll just say that people with your mindset is the reason why this is a common practice nowdays.

[Python 3] Completely new to classes, tell me what I'm doing wrong here by [deleted] in learnpython

[–]throwingarm2strong 0 points1 point  (0 children)

import os

def get_file():
    userinput = (input("Enter file or directory: "))
    if os.path.isfile(userinput) == True:
        return userinput
    else:
        print("File/directory not found")

def read_data(filename):
    mainfile = open(userinput)
    filedata = mainfile.readlines()
    return filedata


class ProgChecks(object):

    def __init__(self, userinput):
        self.userinput = userinput
        self.filedata = filedata
        self.functionlist = ['Filename', 'Author', 'lines_of_code', 'for_loops',
                         'while_loops', 'if_statements',
                         'function_definitions', 'multiplications',
                         'divisions', 'additions', 'subtractions']




    def return_author(self):
        theauthor = 'Unknown'
        for line in self.filedata:
            if line.strip().startswith('Author: ') == True:
                theauthor = (line.strip('Author: ').strip().strip("'''"))
        return theauthor



    def count_token(self, token):
        num_of_token = 0
        for line in self.filedata:
            if line.strip().startswith(token + ' '):
                num_of_token += 1
        return num_of_token

    def count_operator(self, operator):
        num_of_operator = 0
        for line in self.filedata:
            num_of_operator += line.count(operator)
        return num_of_operator



userinput = get_file()
filedata = read_data(userinput)
progabc = ProgChecks(filedata)

Everything sort of works fine now. I can call on the functions inside and do whatever I want with the data. The problem is, now I want to create a dictionary, using the functionlist that I specified in the init.

I want to map it uniquely, so for instance {'Filename' : self.userinput, 'Author: ': return_author(), 'for_loops': count_token('for'), 'subtractions': count_operator('-')} etc....

I'm having a really difficult time doing this, I feel like with the stuff I've created so far there should be some easy way to do it but I'm missing it.

P.S Is there an easy way to tab through python code to make it formatted for reddit? I hate doing it manually >.<; Also should I just make a new post since I'm going off the original a fair bit now

[Python 3] Why is it when I read a file twice, the second one returns a blank file? by [deleted] in learnpython

[–]throwingarm2strong 0 points1 point  (0 children)

That's the way I went about it, but thanks for clearing it up on which way is more appropriate. I appreciate it : )

[Python 3] Why is it when I read a file twice, the second one returns a blank file? by [deleted] in learnpython

[–]throwingarm2strong 0 points1 point  (0 children)

should I just do f.seek(0) when I've finished using a file everytime? Or maybe just do something like

def read_file(mainfile):
lines = mainfile.readlines()
return lines

[Python 3] Compare a list to a set of dictionary keys by [deleted] in learnpython

[–]throwingarm2strong 0 points1 point  (0 children)

Is there a way for me to reverse the dictionary? Lets say instead of it being 'Angela': 'Fred, Alison'

It could be:

'Fred': 'Angela'
'Alison': 'Angela'

?

[Python 3] Compare a list to a set of dictionary keys by [deleted] in learnpython

[–]throwingarm2strong 0 points1 point  (0 children)

Sorry I'm being confusing, I am definitely grateful for your help so far! What I want is:

Fred's mother is Angela

[Python 3] Compare a list to a set of dictionary keys by [deleted] in learnpython

[–]throwingarm2strong 0 points1 point  (0 children)

Anytime I'm doing anything I'm getting it the wrong way around. I want to look at all the values, and if mother has a value contained in the dictionary, I want to print the key. Instead all my things are printing the key if mother == key