I’m making a playlist website that can create display and delete playlists and songs. I’m using a JSON file to store the data. The only feature that isn’t working is the delete song feature. This is my JSON file I’m using the ID of the playlist and the index of the song to locate it in the list and using
Tag: dictionary
Python List to Dictionary from a file
I have a file of notes that im trying to convert to a dictionary. I got the script working but failed to output the data im looking for when there are repeated values. In short took the file commands or comments which are separated by # as per below. I take that list and seperate the 1st column “key” by
How to add aliases to an input dictionary?
Recently I started a project. My goal was it to have a script, which, once launched, could be able to control actions on the hosts computer if an instruction was send via email. (I wanted this so I could start tasks which take a long time to complete while I’m away from home) I started programming and not long after
How to optimise the grouping of values in lists by key in a dictionary list?
The script below works but I was wondering if there is a faster solution? With very large dictionary lists I noticed a small delay. Answer It seems keys in the dictionaries are the same, so you could use a dict comprehension: Another pretty fast alternative is to use the cytoolz module. Output: Timings:
Check for string in list items using list as reference
I want to replace items in a list based on another list as reference. Take this example lists stored inside a dictionary: Then, I have this list as reference: My result should look like this: I want to check if any of the list items inside “wishlist” is inside one of the values of the dict1. I tried around with
Using a column of values to create a counter for a variable sequential number column
I currently have a pandas dataframe with some columns. I’m looking to build a column, Sequential, that lists what iteration is recorded at that part of the cycle. I’m currently doing this using itertools.cycle, and a fixed number of iterations block_cycles, like so: With an output like this: And this would be fine, if the number of iterations in a
How to write dict in file with specific format and headers?
I have a dict: I need to write this data into file line by line in the following format: How to do that using Python? Answer You can change dictionary1 to dictionary2 for other values.
How can I convert a string to dictionary in a manner where I have to extract key and value from same string
I need to convert string to dictionary in a manner for example Output what I require is Note: str1 can have many more such c, d, e with range. Answer You can do it with a regex: Explanation of the regex: match combination of alphanumeric characters and dashes [w-]+ followed by a space, a colon and a space _:_ followed
How to create dictionary from multiple dataframes?
I have a folder with several csv files. Example of the dataframes from csv files in directory: I need to make a function that accepts route to file directory and return sites frequency dictionary (one for all sites in file directory) with unique sites names the following kind: {‘site_string’: [site_id, site_freq]} For our examle it will be: {‘vk.com’: (1, 2),
Assigning dict to class variable converts it to tuple
I’ve been using python for a while and I’ve never run into this. I am passing a dict to a class and assigning it to a class variable like so. If I print the type of rule_list prior to assigning it to self.rule_list I get <class ‘dict’>. Immedietly after assignment, I get <class ‘tuple’>. I want to keep rule_list as