Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
tef
May 30, 2004

-> some l-system crap ->
RIP The old thread.

To open the new thread, here's something I wish I knew all those years ago:


code:
a_string = (
    "One"
    "Two"
    "Three"
)
Gives "'OneTwoThree"

Adbot
ADBOT LOVES YOU

tef
May 30, 2004

-> some l-system crap ->
https://github.com/kennethreitz/pipenv :toot:

tef
May 30, 2004

-> some l-system crap ->
Or use ('Hearts', 12) for the Queen of Hearts

Then if you use a set() instead of a custom container, you can write {card for card in deck if card[0] == 'Hearts'}

If you want, use a namedtuple so you can use card.suit or card.rank

tef
May 30, 2004

-> some l-system crap ->

NtotheTC posted:

Does anyone know if pipenv can replicate the behaviour of vex? (https://pypi.python.org/pypi/vex) I've always found vex to be lightyears ahead of virtualenvwrapper for development (activating and deactivating virtualenvs manually is a horrible pattern) but I've never used pipenv and people seem very happy with it

To be clear, the behaviour I want to replicate is

Bash code:
vex myenv python myscript.py
instead of
Bash code:
workon myenv
python myscript.py
deactivate myenv

pipenv run python myscript.py

tef
May 30, 2004

-> some l-system crap ->
Stick a \u200E in it

https://www.w3.org/International/questions/qa-bidi-unicode-controls

tef
May 30, 2004

-> some l-system crap ->
What's messing up is the bidi algorithm

in the big table of stuff

http://unicode.org/reports/tr9/#Table_Bidirectional_Character_Types

you can see that numbers are weak, so they're influenced by the text surrounding them.

in this case, some implementations see it as part of the hebrew text because it's just numbers, resetting when the encounter a dollar sign, others recognize it as belonging to the dollar sign, or surrouding letters

tef
May 30, 2004

-> some l-system crap ->

The March Hare posted:

Yeah, I just tossed the hard ltr char right after the name and it looks fine now. Thanks~

code:
>>> import unicodedata
>>> def wrap_rtl(name):
...     if unicodedata.bidirectional(name[0]):
...             return "\u200f{}\u200e".format(name)
...     else:
...             return name
... 
>>> name ="\u05dd\u05dc\u05d5\u05d2"
>>> 
>>> print("hi {} 123 hi".format(name))
hi 123 ... hi
>>> print("hi {} 123 hi".format(wrap_rtl(name)))
hi ... 123 hi
:toot:

tef
May 30, 2004

-> some l-system crap ->

Sad Panda posted:

I was learning some Comp Sci and that involved learning about linear search, binary search, bubble sort, insertion sort and merge sort. I decided that the best way to make sure that I understand them was to code them.

It's worth pointing out that many of these algorithms operate on *fixed length arrays* not *python lists*. When you're calling pop, insert, append, you're changing the length of the list, as well as changing the list. With these old algorithms, you probably want to stick to arr[0] = .....

Or maybe, build a new list entirely. The code always gets a bit tricky when you're using one data structure in place of two:

For example: this operates like an insert sort (find smallest, put at end of new list), but it doesn't re-use the front old list to store the values

code:
arr = []
while unsorted:
    smallest = min(unsorted)
    idx = unsorted.index(smallest)
    arr.append(unsorted.pop(idx))
When you're looking at these algorithms, you should try and think about the strategy (over arching goal) or tactics (actions towards goal) they take.

Insertion sort divides the list into two pieces, the smallest element and all elements larger than it. Bubble sort tries to make the list slightly less unsorted with each pass, moving elements to the right position. Both of these strategies can be adapted to build other sorting algorithms, and sometimes the tactics from the 60's and 70's aren't as valid today

You could make different tactics: like keeping the min, max as you scan through the list, and build up a new list from either end. Or perhaps change the strategy: break the list into (smaller than, bigger than) rather than (min, bigger than). Then sort either half.

You can start to develop a feel for different ways to sort structures. It might be worth looking at how python does it too, it uses a wonderful trick: Break the list into pre-sorted chunks and merge them. It's a little of both worlds: Scanning through a list to find out of place elements, and breaking the list down into smaller pieces to operate on.

Adbot
ADBOT LOVES YOU

tef
May 30, 2004

-> some l-system crap ->
It's in a list

Python has collection types, dict, and list, which are used for json arrays and objects:

code:
x  = ["a", "b", "c"]
x[0] # is "a"
x[0] is asking for the 0th element of the list. Yes, it's 0-indexed.

If you're asking questions like this, you might want to run through, or skim over the python tutorial, just to get a feel for some of the names of things.

https://docs.python.org/3/tutorial/

You can pick the right version of the tutorial to match your version of python

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply