All New

user:thomas gists created by user

title:mygist gists with given title

filename:myfile.txt gists having files with given name

extension:yml gists having files with given extension

language:go gists having files with given language

Login


All New Login
's Avatar

kristofer

Joined 1714567308

Recently created
Least recently created
Recently updated
Least recently updated
All gists 111
kristofer's Avatar

kristofer / TastyHint3.md

0 likes
0 forks
1 files
Last active 1731421149

I'm struggling to see where we take the user input for the task name.

the command variable will have exit or whatever, right?

and the new <task> will actually look like new Buy Milk

so take the string and split it into a list of strings, breaking each string on the character.

kristofer's Avatar

kristofer / TastyHint2.md

0 likes
0 forks
1 files
Last active 1731350954

If we have thought about this:


tasks = {}   # creates an empty dictionary

tasks['Buy Milk'] = 'not yet'
tasks['Start Lab'] = 'completed'
kristofer's Avatar

kristofer / TastyHint1.md

0 likes
0 forks
1 files
Last active 1731350546

Remember start very small and build outward.

Hint 1

If you haven't already decided how to start...

This is the tasks variable.

    Tasty class.
kristofer's Avatar

kristofer / Some Bad Habits in Python

0 likes
0 forks
1 files
Last active 1731081231

One More List of Bad Habits

Also, be aware that some of these things are not actually related to Python but are considered to be bad practices in most of the languages (like Java).

  • No comments is bad — people forget and you should comment your code. Describe why not how. Explain the intent behind the code.
  • Too many comments is also bad — you should feel the border line at column 80.
  • No abstractions is bad — they didn’t develop Python for you to write Assembly-style wall of code with no functions and/or classes. Copy-pasting your code is bad — use functions when you
kristofer's Avatar

kristofer / Is Pythonic?

0 likes
0 forks
1 files
Last active 1753282976
some examples of good and bad pythonic snippets

Pythonic code refers to code that is written in a way that is idiomatic to Python, taking advantage of its features and conventions to produce clear, concise, and readable code. Here are some examples showcasing Pythonic principles:

1. List Comprehensions

Not Pythonic:

squares = [] 
kristofer's Avatar

kristofer / dict-count.py

0 likes
0 forks
1 files
Last active 1731079542
a sample of frequency counting words from a list, in good and bad styles
1 # You need to write a loop that counts the occurrences of each word in a list.
2 #
3 # Consider, if you had a big str that was a text, like say: https://zcw.guru/kristofer/hamlet
4 #
5 # strive to be "pythonic" in your code expressions, okay?
6
7 colors = ["red", "green", "blue", "green", "red", "green"]
8
9 # Not Pythonic Code
10 d = {}
kristofer's Avatar

kristofer / Hamlet by Shake-speare

0 likes
0 forks
1 files
Last active 1731079354
1 THE TRAGEDY OF HAMLET, PRINCE OF DENMARK
2
3
4 by William Shakespeare
5
6
7
8 Dramatis Personae
9
10 Claudius, King of Denmark.
kristofer's Avatar

kristofer / Details Matter

0 likes
0 forks
1 files
Last active 1729274913
a small difference makes results wildly different
1
2 public class WhoaWhat {
3 public static void main(String[] args) {
4 System.out.println(doOne() + " " + doTwo());
5 // will print 2048 4 - but why?
6 }
7 private static int doOne() {
8 int result = 2;
9 for(int i = 0; i < 10; i++)
10 {
kristofer's Avatar

kristofer / BugReporter (java)

0 likes
0 forks
1 files
Last active 1727273021
cool class from https://github.com/RohitAwate/Everest/blob/master/BugReporter/src/BugReporter.java
1 /*
2 * Copyright 2018 Rohit Awate.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
kristofer's Avatar

kristofer / Quine-Py

0 likes
0 forks
1 files
Last active 1727095994
A quine is a clever bit of code that outputs its own source code.
1 # Quine - Program That Reproduces Itself
2 # A quine is a clever bit of code that outputs its own source code.
3 # It’s like looking in the mirror and seeing… well, your code staring right back at you.
4
5
6 s = 's = {!r}; print(s.format(s))'; print(s.format(s))
7
8 #output => s = 's = {!r}; print(s.format(s))'; print(s.format(s))
Newer Older

Powered by Opengist ⋅ Load: 137ms⋅

English
Čeština Deutsch English Español Français Magyar Italiano Português Русский Türkçe Українська 中文 繁體中文