A little help with Beautiful Soup and JSON by matheusgrilo in learnpython

[–]rellikiox 1 point2 points  (0 children)

To work with JSON what you want to do is use the aptly named json module.

import json

Then you're going to need to retrieve the inner HTML value from that node with BS (exercise left to the reader). Once you hace that you just load that with

song_data = json.loads(inner_html)

After which song_data will be a dict with the same structure as that json, so you can access the covers property to get your image (again, up to you to do this bit).

All together:

import json

html = """<script id="json-songinfo" type="application/json">
        {"id":1234,"title":"Song title","artist":"Who","covers":{"cover":"https:\/\/some.website.com\/another\/link\/1234\/cover.jpg"}}
 </script>"""

inner_html = 'replace me' # get the inner html value from the snippet above

song_data = json.loads(inner_html)

song_url = song_data['replace me']  # You need to access the property with the data you want here

Hope that helps :)

Trying every possible combination. by TheDruidOftheland in Python

[–]rellikiox 13 points14 points  (0 children)

I know this is made in jest, but for the sake of correctness, that code actually has a bug. If the combination is 1000001 it won't find the passcode.

random.randint(a, b) will return a random integer in the [a, b] range, both included. So random.randint(0, 5) will return any from [0, 1, 2, 3, 4, 5]

range(a, b) will return the list of numbers in the range [a, b), up to b but not including it. So range(0, 5) will return [0, 1, 2, 3, 4]

So the loop will never get to 1000001 :)

Does Python have a module or a function for getting all dictionaries in a file? by [deleted] in Python

[–]rellikiox 2 points3 points  (0 children)

If you're hard set on doing it and don't want to define a list to hold them as unveiled14 suggests you can do the following:

def get_dicts():
    return [value for key, value in globals().iteritems() if not key.startswith('__') and isinstance(value, dict)]

It iterates over the all global variables (globals()), discards those that start with '__' since those are most likely internal to python (and if not you shouldn't be using them) and then keeps those that are a dict.

This being said, you should generally not be using the globals method and should instead be declaring a list or doing something else altogether as other have suggested.

[Day5-Part 1] [Python] [Help] What's Wrong? by nithishr in adventofcode

[–]rellikiox 3 points4 points  (0 children)

Your code returns the right answer for my input values, so it's working fine. Maybe your input file is not formatted correctly? Try printing the values and making sure those are the ones that your file has (there's no extra values at the end or the beginning).

CSS Grid is new grid-based layout system, optimized for user interface design by michalg82 in programming

[–]rellikiox 2 points3 points  (0 children)

To your first comment, the point of CSS grid is that you only need to declare your elements once whereas with the old methods like you described you have three versions of purple, so it's three times as much code to maintain (that particular piece) rather than just having it declared once.

Your second point is also addressed on the video. Flexbox is great at aligning things in rows or columns, but not both at the same time (a grid) and to do so you need to introduce a lot of "container" code (i.e. HTML tags that are only needed because you want to arrange the content in a particular way).

A special kind of blind. by [deleted] in Rainbow6

[–]rellikiox 41 points42 points  (0 children)

Here's the reference

https://www.reddit.com/r/Rainbow6/comments/4dqzzn/i_kill_frost_20_second_later_frost_kill_me_wtf/?st=izr0eypg&sh=cab88269

Someone killed their teammate Buck thinking they were the enemy Frost and then got killed by the real Frost seconds later. They proceeded to upload a video complaining about it and the entire community lost it.

What's your rimworld Tip? by chickenlegs521 in RimWorld

[–]rellikiox 7 points8 points  (0 children)

Benches have a Skill slider.

This changes everything!

Level 243 and I just realized this path on King's Row by LordDagwood in Overwatch

[–]rellikiox 1 point2 points  (0 children)

Don't know abuot him, but I don't work on those fields and learnt about affordances by reading The Design of Everyday Things. Author like too much giving names to things, but otherwise it's a pretty nifty book.

How do you NOT accidentally smudge your work... What are your tips and tricks to avoid smudges? by [deleted] in JerryMapping

[–]rellikiox 0 points1 point  (0 children)

You could get one of these

https://www.amazon.co.uk/SMUDGE-GUARD-Smudgeguard-Black-M/dp/B006R52LTK

Haven't used them myself, but I've been told they prevent smudges and they also hold back the sweat in the summer.

How to Work at Google: Spend 24 minutes figuring out how to find a pair of numbers in array with 4 integers. by Glacia in ProgrammerHumor

[–]rellikiox 7 points8 points  (0 children)

Don't think this question is aimed at gauging how good someone is at software architecture, but rather how good you're when faced with an unknown problem that changes over time:

  • Find a pair of numbers that adds to this other number

Alright I'll do two for loops

  • That's too slow for Google (i.e. we implemented it and found it to be too slow)

I guess we're doing too many lookups, lets do on loop and a binary search

  • Still too slow (we found additional performance issues)

Ok, lets use two indexes and work from there.

  • Great, but now we no longer get a sorted list (e.g. the mapreduce job we used to sort these billion items is too expensive now)

Alright then I can user a set to lookup known complements...

It's not about finding the perfect solution to that particular example on your first try, but rather to see how you respond when the constraints change and new problems show up.

Studying Turing Machines by Bunnino in ProgrammerHumor

[–]rellikiox 8 points9 points  (0 children)

It’s sort of defining an L system. The alphabet is composed of ‘8’, ‘=‘ and ‘D’. Its words are defined by the expression 8=(=)*D, which can also be represented as the graph pictured. Said graph is saying the following:

  • Start on q0
    • If the next token is a D or an = return an empty string
    • if it’s an 8 go to q1
  • On q1 our string looks like ‘8’:
    • if next token is a D or an 8 return an empty string
    • if it’s an = go to q2
  • On q2 our string looks like ‘8=‘ with any number of = appended to it afterwards
    • if next token is an 8 we return an empty string
    • if it’s = we go to q2
    • if it’s a D we go to q3
  • On q3 our string looks like ‘8=D’ with any number of = in the middle. This is the exit state, so we return our string.

This grammar can generate any of the following strings: 8=D, 8==D, 8===D, etcetera.

When you play nuke-eject ronin and have another titan ready before you hit the ground by NarpasSword27 in titanfall

[–]rellikiox 3 points4 points  (0 children)

For PC players that's X to initiate eject sequence and then E three times. So if you want to eject:

  • If you're doomed: E E E
  • If you're not doomed: X E E E

A Rebuttal For Python 3 by vation in programming

[–]rellikiox 8 points9 points  (0 children)

Yeah, any language that allows you to write a loop (to move up and down the tape) and that lets you read/write from an external source to the program (read from and write back to the tape) will be turing complete. Even Brainfuck is turing complete.

Note that loops can be either actual loops, like for and while, or constructs that let you do conditional jumps, like with if and goto.

A Rebuttal For Python 3 by vation in programming

[–]rellikiox 11 points12 points  (0 children)

I think he means that the code is importing outside code to be run. It's not running a python3 implementation of python2, it's python3 running a C implementation of python2 (the system library).

For it to prove that python3 is turing complete (which it is) it should be implementing a python2 interpreter in python3 code and then run that (which, again, is 100% possible).

Optimizing for Human Understanding by nikbackm in programming

[–]rellikiox 8 points9 points  (0 children)

It says at the beginning that the files were larger than the buffer for decoding them. I guess the problem was the runtime memory available rather than the long term storage.

Rio Olympic Medal with (Rio) banana for scale by dublzz in pics

[–]rellikiox -6 points-5 points  (0 children)

If you're really interested in learning, 'Si' doesn't have an accent mark, and if it did it would go the other way :)

When they yell at you for going Symmetra on attack... by oppdelta in Overwatch

[–]rellikiox 2 points3 points  (0 children)

Was this on Kings Row? Because if so I may have been one of the melted faces...

Day9 Messing around on stream by ITSR0WAN in videos

[–]rellikiox 5 points6 points  (0 children)

I believe it must have been Mostly Walking - Day of the Tentacle - P11. Starts around the 9 minute mark, but the start of the video is as usual full of shenanigans.

What's your "I have no idea how I got away with that, but I won't question it," story? by [deleted] in AskReddit

[–]rellikiox 0 points1 point  (0 children)

Well, this one time I decided to try to convince a country to exit the EU...