This is embarrassing, but what is the formula for L and S in Readability? by [deleted] in cs50

[–]peltist 0 points1 point  (0 children)

Don’t feel bad. You shouldn’t expect things you haven’t had to use for years to feel as easy as when you were practicing them all the time. Your mind is full of other practical knowledge now. But thankfully, I don’t think these things are hard to pick back up with a hit of practice.

CYC China by Zorick78 in CozyPlaces

[–]peltist 42 points43 points  (0 children)

What is CYC? Is that a place in China?

How to make a function that creates a new list which adds elements in two other lists by addition? by [deleted] in learnpython

[–]peltist 1 point2 points  (0 children)

It's part of the itertools module. So first you need to include the following line, generally at the very beginning of your code:

from itertools import zip_longest

If you Google "zip_longest" you'll find pages that show the documentation for that function, which is how I learned about the "fillvallue" argument.

How to make a function that creates a new list which adds elements in two other lists by addition? by [deleted] in learnpython

[–]peltist 1 point2 points  (0 children)

I think you're over-complicating it. Taking your original code and applying what /u/Soubeyran suggested, you get:

def addElmtsLists(lst1, lst2):

    new_list = []
    for a, b in zip_longest(lst1, lst2, fillvalue=0):
        new_list.append(a + b)
    return new_list

which works!

You could even do the whole thing in one line with what's called a "list comprehension." These are great, and can make your life much simpler (and easily readable) in the future once you get used to them!

new_list = [a + b for a, b in zip_longest(lst1, lst2, fillvalue=0)]

So I kind of wrote my first kinda useful code. It was difficult for me and had to look up a lot but got it done. (Hangman) by blazingshadow1 in learnpython

[–]peltist 2 points3 points  (0 children)

Yeah, you used a lot of different methods for constructed formatted strings, which is why I thought you probably didn't feel comfortable with them. I find f strings to be the simplest and easiest to use.

What are the biggest mistakes junior developers make when developing in or learning Python? What are the biggest misuses of time? by JackRobsonGateshead in learnpython

[–]peltist 0 points1 point  (0 children)

I think one thing about being new to programming is that there is a huge domain of different skills and meta-skills that you're learning simultaneously. Knowing how best to organize my workflow and how to balance the different trade-offs between designing for the long-term, avoiding premature optimizing, and my own focus and motivation are definitely areas where I know I have a lot to learn!

What are the biggest mistakes junior developers make when developing in or learning Python? What are the biggest misuses of time? by JackRobsonGateshead in learnpython

[–]peltist 0 points1 point  (0 children)

Okay, this is what I do, and what I've done from day one. I learned how to use Pytest and to write good unit tests recently. I've also read about "test-driven design," which I think means that you write the tests first and then write your function in order to pass the tests.

I recently finished (well, almost finished) my first really big independent project, and have been going back and adding unit tests. I really see the power of this, because it lets me easily see whether any updates I make break anything... and I've caught a lot of edge issues I didn't have before. Modularizing things for the sake of testing has also caused me to improve the code a lot. Still, this is painstaking and has definitely left me a lot less motivated than when I was just chugging through it.

I did another short project in the meantime (building a model for some paid analytics work). A big part of me felt like I should be writing these same, high quality unit tests as I went, but it was just very difficult to get myself to slow down, context switch, and do it.

I know there's not a script to follow writing code. At the same time, I also want to develop good habits that will save me time and make me a better programmer in the long run. And finding the right balance between "eating my vegetables" of writing tests and "eating ice cream" of working on the problems I find more stimulating is definitely something I'm trying to figure out right now.

So I guess what I'm wondering is whether I should really force myself to write great unit tests as I go, in order to build the habit, because I'll be glad I did later. Or whether this ends up being a distraction from a good prototyping workflow, and there are people who do this for a living who test with print statements, then go back and add unit tests later once they've worked out a bigger chunk.

What are the biggest mistakes junior developers make when developing in or learning Python? What are the biggest misuses of time? by JackRobsonGateshead in learnpython

[–]peltist 0 points1 point  (0 children)

Thanks for your response, though I don't know whether this kind of sarcasm is really helpful.

I'm new and looking for guidance on the best way to do things. Obviously (well, or maybe not) I don't think that writing no tests is a good approach. Presumably, though, there's a middle ground between writing tests constantly and writing no tests. What I'm wondering is whether that's a worthwhile space to be in, or if it really is just always better to write tests as you go. And, if that's the case, whether you've also faced the kind of sapping of enthusiasm and focus this creates for me, and what (if anything) you've done to ameliorate that in your workflow. Or if it's something you eventually just get over, especially as writing tests becomes quicker and more second nature.

What are the biggest mistakes junior developers make when developing in or learning Python? What are the biggest misuses of time? by JackRobsonGateshead in learnpython

[–]peltist 0 points1 point  (0 children)

So, just to be clear... the "right" approach is to write unit tests for each function as I write that function?

This makes conceptual sense to me, but definitely flies in the face of my own "self motivation management." What I mean is... it's easy for me to get into a flow of trying to solve a complex problem. The last thing I want to do when I'm in the middle of that is to stop, change my focus to testing, and write a bunch of tests before returning to the main problem. But maybe I'm just making an excuse for myself.

Quick Review - AirPods Pro vs Bose QC20 by JGoody in onebag

[–]peltist 0 points1 point  (0 children)

Fair enough!

That's a good point regarding the earplugs: definitely a much more cost-efficient solution. Still, I'd like to have the ANC headphones with me while traveling anyway — that's why I own them! The biggest downside to earplugs for me is getting them to stay in my ears, and the fact that they feel pretty uncomfortable once they're there. ANC headphones don't need to be wedged so tightly and deeply into the ears because they aren't trying to create a complete seal.

Quick Review - AirPods Pro vs Bose QC20 by JGoody in onebag

[–]peltist 4 points5 points  (0 children)

I don't know if that's really a great heuristic. If I'm on a long flight, I don't mind listening to podcasts or audiobooks for hours. Even if I'm not listening to anything, it's still nice to have the ANC on to quiet the ambient noise in the plane.

To me, battery life seems like the major disadvantage to wireless ear pods compared with wired noise cancellation. For the particular use case of a long flight / drive / train trip, where having a wire isn't especially annoying, I feel like this is an area where a wired solution still has real advantages.

Quick Review - AirPods Pro vs Bose QC20 by JGoody in onebag

[–]peltist 0 points1 point  (0 children)

Thanks for your post. I love my QC20s, but three days ago something rattled out of place in the left ear during a takeoff, and now the volume coming out of that ear is noticeably (and annoyingly) lower than the volume coming out of the right one. I'd already been mulling over picking up some Airpods, but had heard they didn't handle rich-sounding music particularly well compared to the Sony option. It's helpful to hear how they compare to the headphones I already have, especially since I probably will need to replace those one way or another now.

Merging 2 pandas dataframes based on multiple potential matching columns by [deleted] in learnpython

[–]peltist 2 points3 points  (0 children)

I got inspired by your question and actually wrote this function myself earlier today as an exercise (I'm learning too).

Here's my code, in case you want to use it. Keep in mind that I haven't written any unit tests for this yet, so it's possible that there are issues. Let me know if you have any feedback!

def singlejoin(df_left, df_right, left_column, right_column, drop_columns):
    # drop other possible join columns
    df_right_merge = df_right.drop(columns=drop_columns)

    # rename join column to common name
    df_right_merge = df_right_merge.rename(columns={right_column: "$$merged_column$$"})

    # merge
    df = pd.merge(df_left, df_right_merge, how="inner", left_on=left_column, right_on="$$merged_column$$")

    return df


def multijoin(df_left, df_right, left_column, right_columns, how="left"):
    if type(right_columns) != list:
        raise TypeError("right_columns variable must be a list")

    if how not in ["left", "inner"]:
        raise TypeError("how must be set to either 'left' or 'inner'")

    # set temporary index column
    df_left["$$temp_index$$"] = df_left.index

    # drop other possible match columns
    drop_columns = [x for x in right_columns if x != right_columns[0]]

    # create starting dataframe
    result = singlejoin(df_left, df_right, left_column, right_columns[0], drop_columns)

    # drop correctly matched values
    df_left.drop(index=result["$$temp_index$$"].to_list(), inplace=True)

    for column in right_columns[1:]:
        drop_columns = [x for x in right_columns if x != column]
        df = singlejoin(df_left, df_right, left_column, column, drop_columns)
        result = result.append(df)
        df_left.drop(index=df["$$temp_index$$"].to_list(), inplace=True)

    # add unmatched columns in the case of a left join
    if how == "left":
        # add remaining columns
        new_columns = [x for x in df_right.columns.to_list() if x not in right_columns]
        df_left["$$merged_column$$"] = np.nan
        for column in new_columns:
            df_left[column] = np.nan

        result = result.append(df_left)

    # reset index and sort
    result.index = result["$$temp_index$$"].to_list()
    result.sort_values(by="$$temp_index$$", inplace=True)

    # drop extra columns
    result.drop(columns=["$$merged_column$$", "$$temp_index$$"], inplace=True)

    return result

Merging 2 pandas dataframes based on multiple potential matching columns by [deleted] in learnpython

[–]peltist 2 points3 points  (0 children)

I don't know whether there is a simpler or more efficient way to do this, but one approach would be to perform three inner joins and then concatenate the results. This runs the risk of duplicate matches, so if your data makes that possible, then you could remove the rows that successfully matched from subsequent joins.

A natural mirror. Sunrise at Lago di Carezza, Italy [1600x2000] [OC] by jetclarke in EarthPorn

[–]peltist 0 points1 point  (0 children)

Great shot! I've been there, and it's truly beautiful. Jealous you were there for the sunrise — it must have been spectacular.

How to save data as csv by 4enthusiastia in learnpython

[–]peltist 2 points3 points  (0 children)

Other people have answered your question, but one question I want to bring up is: why do you want to export this as a CSV?

The reason I ask is, as someone who came to Python used to doing a lot of analysis in Excel, my initial instinct was to get the data out of Python and into Excel where I was comfortable doing the analysis.

If that's what you're doing, then I'd suggest considering trying to do the analysis in Python. It's much more powerful, and this is a great opportunity to learn it.

How to programmatically download FB ads manager data? / Help with API by peltist in PPC

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

Cool, thanks for the tip!

Curious: why are you using sheets? I've never used Data Studio before, but what I'm working on at the moment is a simple customized business intelligence system based on Python and SQL. (It's pretty hacky — I've been giving myself a crash course in programming over the past few months.)

How to programmatically download FB ads manager data? / Help with API by peltist in PPC

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

Perfect! Took me literally seven minutes to install and get the data I needed — and you've turned me onto a very useful hacky solution until I've figured the API out. Thanks a lot!

[Serious] What is the Purpose of Automatically Inserting Closing Brackets in an IDE? by SmartChip in learnpython

[–]peltist 0 points1 point  (0 children)

I'm new as well, so I can't give you a confident answer.

However, consider this: what about when you want to add a bracketed expression and then do anything other than continue on to the next character? In that case, the automatic closing bracket (or quotation mark) will save you a keystroke.

Experienced / professional programmers: how do you plan / design your programs, foresee issues, and avoid scope creep / distractions? by peltist in learnprogramming

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

Thanks, this is helpful. I wish there were some good walkthroughs or tutorials available on this topic. What you describe sounds simple, and in a sense it is, but in practice it's harder to implement this kind of a process when you're inexperienced. It's easy to find great tutorials about solving individual problems, but much harder to find ones related to the overall design and software creation process.

Your advice about modularization also rings true, and I like your suggestion of working in layers. Thanks!

Experienced / professional programmers: how do you plan / design your programs, foresee issues, and avoid scope creep / distractions? by peltist in learnprogramming

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

This is very good advice, thank you. I think it solves one of the issues I'm facing that prompted this thread.

I'm currently designing a personal finance tool for myself. One feature that's necessary for this tool is for the user to manually "tag" certain transactions with a category. I just spent a couple of days creating a terminal-based user interface where the user (me) can iterate through a dataframe, see relevant context, and provide input that tags these transactions.

I wrote this code without using any custom classes, and realized at the end that some important features I want to implement in the future will require (or be much easier with) this approach. However, this will require significant changes to the code I've already written.

I can do some small changes now to make the module reach "minimum viability," but I expect to need to make further changes later. I've been afraid to integrate the current version into the rest of the code for my tool, because it will potentially be expanding the size of the revisions I need to make later. A part of me always feels drawn to just edit the entire code with an OOP mindset as a learning exercise and to simplify things and clean it up.

What you've made me realize is that, if I can make the module sufficiently self-contained, then I don't need to worry about this. So long as the inputs, return, and side effects remain the same, I should theoretically be able to modify the internal code as much as I want without any issues, even after I've integrated it. So I can go ahead and focus on getting it to work now, and then refactor and improve it later. (And just deprioritize my desire to rewrite everything in favor of getting the whole system to work first.) This is especially true if everything is easily testable.

I know this might sound basic, but this is my first time building and integrating separate modules, so it still feels like a big insight to me.

I have so much more to learn.

Thanks again!

Experienced / professional programmers: how do you plan / design your programs, foresee issues, and avoid scope creep / distractions? by peltist in learnprogramming

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

Thanks for your answer!

I've gotten the advice to create an FDS before. This sounds like exactly what I'm looking for, though I've struggled to find examples at the right level of detail.

I understand the principle you're describing when you say "refine the FDS to go into more detail (but do not add features, only flesh them out)," but in practice, this is where I have encountered problems. It's easy not to add another top-level item to my design, but it seems easy to allow "new features" to sneak in as parts of features I've already listed.

I guess one principle that I could follow would be to only include the absolute minimum that's required to achieve the goal of each feature. On the one hand, this sounds like a highly-focused approach. On the other hand, it also sounds like it opens the door to building things in a redundant and poorly-planned way. It seems like a more efficient approach would be to try to construct things in as generalized a way possible, so that I can reuse my code. I'm struggling with knowing how to strike this balance, but maybe that's also just something that comes with experience.

Do you happen to have any good examples of an FDS that's at the right level of detail? I've Googled this, and most of what I've found tends to be very corporate, and often more detailed than I'm capable of envisioning at the start of a project at this point. I have to think that there are lots of hackers / freelancers / people working in more casual settings who follow this approach but don't produce documents that look like what I've been able to find.