[Solved] Python Defining Lists in Lists

Lists don’t take name-value pairs. You probably want dictionaries here instead: definitions = { ‘title_label’: { ‘text’: (236, 218, 51), ‘background’: (125, 142, 246) }, ‘start_button’: { ‘text’: (32, 40, 145), ‘background’: (236, 235, 136), ‘pressed’: (44, 51, 112) }, ‘quit_button’: { ‘text’: (166, 21, 13), ‘background’: (48, 61, 188), ‘pressed’: (31, 40, 129) } … Read more

[Solved] I can’t figure out this sequence – 11110000111000110010

There are many possible solutions to this problem. Here’s a reusable solution that simply decrements from 4 to 1 and adds the expected number of 1’s and 0’s. Loops used : 1 def sequence(n): string = “” for i in range(n): string+=’1’*(n-i) string+=’0’*(n-i) return string print sequence(4) There’s another single-line elegant and more pythonic way … Read more

[Solved] Convert lists to dict python? [closed]

try: lsts = [[“key=fvv”,”val=34″],[“key=djbjd”,”val=22″]] result = {i[0].split(“=”)[1]: i[1].split(“=”)[1] for i in lsts} print(result) output {‘fvv’: ’34’, ‘djbjd’: ’22’} solved Convert lists to dict python? [closed]

[Solved] Sorting a python list based on date? [closed]

try, and you will get you expect sort In [51]: a=[[‘xX0001’, ‘10006’, ‘102’, ”, ‘2018-02-02’, 3233.9, 0.0, 36816.18, ”], …: [‘xX0001’, ‘10006’, ‘102’, ”, ‘2018-02-01’, 4142.45, 0.0, 40146.55, ”], …: [‘xX0001’, ‘10006’, ‘200’, ”, ‘2018-02-02’, 14367.539999999999, 0.0, 41496.42999999999, ”], …: [‘xX0001’, ‘10006’, ‘200’, ”, ‘2018-02-01’, 12663.27, 0.0, 56043.94, ”]] In [52]: sorted(a, key=lambda b: b[4]) … Read more

[Solved] How to use a function after definition?

Clearly speed is a parameter for the function, so pass it to the function as an argument, not via a global variable. def journey(knots): ”’Convert knots to kilometres per day”’ return round(knots * 1.852 * 24) >>> speed = 5 # in knots >>> print(“Ship travels {} kilometres in one day”.format(journey(speed))) Ship travels 222 kilometres … Read more

[Solved] How to make a this specific Pattern [closed]

There’s two different ways to go about this: Build a parser – much work, but very flexible and possibly best performance (depending on implementation) Use a regular expression. In your case this could be something like (\d{2,3}\.)+\d{2,3} (shortest string matched should be “111.11”) 2 solved How to make a this specific Pattern [closed]

[Solved] Python can’t implement timeit module [closed]

You seem to have misinterpreted the function of timeit.timeit – the idea is that you tell it what to actually time, and it then times it. Normally, it does the thing you’re timing many, many times, so you can get a meaningful average. This means it also needs to provide a ‘setup’ argument, as the … Read more

[Solved] Python get info from long complicated string

You can use re module for the task: style=”fill: rgb(0, 0, 0); fill-opacity: 1; font-family: ProjectStocksFont; font-size: 70px; font-weight: normal; font-style: normal; text-decoration: none;” import re print( re.search(r’font-size:\s*(\d+)’, style)[1] ) Prints: 70 3 solved Python get info from long complicated string

[Solved] How to convert a list to dict using python [closed]

A dictionary comprehension can do this: {item[0]: item[1:] for item in inputlist} As your input elements are tuples, your output values are tuples too: >>> inputlist = [(u’name1′, (47.5320299939, 7.70498245944), (47.5321349987, 7.70499587048), (47.5319710886, 7.70484834899), (47.5320299939, 7.70498245944)),(u’name2′, (47.5320299939, 7.70498245944), (47.5321349987, 7.70499587048), (47.5319710886, 7.70484834899), (47.5320299939, 7.70498245944))] >>> {item[0]: item[1:] for item in inputlist} {u’name2′: ((47.5320299939, 7.70498245944), (47.5321349987, … Read more