[Solved] Python: Sorting list in dictionary by key name

You need to sort the other lists based on the order of ‘Functions’, and sort that list last. One way to implement this is using zip to combine e.g. ‘Functions’ and ‘Action’ into a single list [(‘Transfer Amount’, ‘N’), …], sort that, then extract the second value from each pair (using e.g. map and operator.itemgetter): … Read more

[Solved] Printing list shows single quote mark

Here’s one utility function that worked for me: def printList(L): # print list of objects using string representation if (len(L) == 0): print “[]” return s = “[” for i in range (len(L)-1): s += str(L[i]) + “, ” s += str(L[i+1]) + “]” print s This works ok for list of any object, for … Read more

[Solved] Convert PDF to Excel [closed]

Getting data out from a pdf file is pretty messy. If the pdf table is ordered and has got a unique pattern embedded along with it, the best way to get the data is by converting the pdf to xml. For this you can use: pdftohtml. Installation: sudo apt-get install pdftohtml Usage: pdftohtml -xml *Your … Read more

[Solved] Check if n is in array [closed]

If I was developing this, I would: Keep all the words in a single set Skip the first question (you can determine word length by the length of the 2nd question) Set up a while loop for each question you ask the user so that it repeats the same question on invalid input. To check … Read more

[Solved] Highest number of consecutively repeating values in a list

I don`t really understand the question, but if you want the highest number of consecutive elements in list, maybe something like this from itertools import groupby list = [1,1,1,0,0,1,1,1,1,1] count_cons_val = [sum(1 for _ in group) for _, group in groupby(list)] print(max(count_cons_val)) Output: 5 solved Highest number of consecutively repeating values in a list

[Solved] What can I do to be able to have numbers with no symbols?

This is an indentation error. The if statements that print the password at the end are inside the symbol_want if statement. You need to unindent the print statements by one level, and it will work fine. import random def password(): normal_adjectives = [‘Funny’, ‘Amazing’, ‘Infinity’, ‘Fabulous’, ‘Red’, ‘Rainbow’, ‘Adorable’, ‘Adventurous’, ‘Impressive’, ‘Determined’, ‘Delighted’, ‘Scary’, ‘Active’, … Read more

[Solved] Extract data from span tag within a div tag

I would use the BeautifulSoup library. Here is how I would grap this info knowning that you already have the HTML file : from bs4 import BeautifulSoup with open(html_path) as html_file: html_page = BeautifulSoup(html_file, ‘html.parser’) div = html_page.find(‘div’, class_=’playbackTimeline__duration’) span = div.find(‘span’, {‘aria-hidden’: ‘true’}) text = span.get_text() I’m not sure if it works, but it … Read more

[Solved] Python: ASCII letters slicing and concatenation [closed]

I think you are misunderstanding the “:” notation for the lists. upper[:3] gives the first 3 characters from upper whereas upper[3:] gives you the whole list but the 3 first characters. In the end you end up with : upperNew = upper[:3] + upper[3:] = ‘ABC’ + ‘DEFGHIJKLMNOPQRSTUVWXYZ’ When you sum them into upperNew, you … Read more

[Solved] I have a list of file names and I need to be able to count how many of the same file gets repeated for each file name [closed]

If you already have a list of filenames use collections.Counter: from collections import Counter files = [“foo.txt”,”foo.txt”,”foobar.c”] c = Counter(files) print (c) Counter({‘foo.txt’: 2, ‘foobar.c’: 1}) The keys will be your files and the values will be how many times the file appears in your list: solved I have a list of file names and … Read more

[Solved] Python sort multi dimensional dict

First, you should avoid using reserved words (such as input) as variables (now input is redefined and no longer calls the function input()). Also, a dictionary cannot be sorted. If you don’t need the keys, you can transform the dictionary into a list, and then sort it. The code would be like this: input_dict = … Read more