[Solved] Split list of lists in new list [closed]

You may simply map the split, filter if it makes a size 2 tuple, and zip it to get the values separately: In[9]: l=[‘Name’, ‘AMAZON.COM – TOT RETURN IND’, ‘AMAZON.COM INC – NET CASH FLOW – FINANCING’, ‘AMAZON.COM INC – NET CASH FLOW – INVESTING’, ‘AMAZON.COM INC – NET CASH FLOW-OPERATING ACTIVS’, ‘AMAZON.COM INC – … Read more

[Solved] How to create a UI in Python [closed]

For start i suggest for you to start with Tkinter library (built in library). This is a simple program using Tkinter gui. import Tkinter class simpleapp_tk(Tkinter.Tk): def __init__(self,parent): Tkinter.Tk.__init__(self,parent) self.parent = parent self.initialize() def initialize(self): self.grid() self.entryVariable = Tkinter.StringVar() self.entry = Tkinter.Entry(self,textvariable=self.entryVariable) self.entry.grid(column=0,row=0,sticky=’EW’) self.entry.bind(“<Return>”, self.OnPressEnter) self.entryVariable.set(u”Enter text here.”) button = Tkinter.Button(self,text=u”Click me !”, command=self.OnButtonClick) button.grid(column=1,row=0) … Read more

[Solved] List to dict: incorrectly sorted result

>>> from collections import OrderedDict >>> sorted_dict = OrderedDict() >>> dct = {1: 2, 3: 4, 4: 3, 2: 1, 0: 0} >>> dct.values().sort() >>> for x in sorted(dct.values(), reverse=True): … keys = [idx for idx in dct if dct[idx]==x] … for key in keys: … sorted_dict[key] = x … >>> >>> sorted_dict OrderedDict([(3, 4), … Read more

[Solved] Python finding best fit line

I’m not sure what you’re trying to do because I don’t understand your question that well. Unfortunately, the code runs insanely slow. (It takes about 75 minutes to complete.) Mabey you should look for a different solution. I copied it out for the image and got: x = [1.0, 2.0, 3.0] y = [1.0, 3.0, … Read more

[Solved] Basic Python Functions (Mathematics involved)

The formula is pretty basic, it say: The function ‘f’ for provided argument ‘S’ returns value ‘K’ if value ‘S’ is less or equal then the value ‘K’, if the value ‘S’ is greater then the value ‘K’ AND lower then the value ‘2*K’ – return value ‘2*K-S’, otherwise return 0. Python: def A(S,K): result … Read more

[Solved] How to test Generators in Python 3. It gives error all the time

Yes, a generator can’t be equal to a string. When your call your function: get_objects(“anything”), it returns a generator object you can iterate over to get the values. If you want to check if the ith element returned is equal to something, do: for i, elem in enumerate(get_objects(“bla bla”)): if i == 3: return self.assertEqual(elem, … Read more

[Solved] i’ve generated random numbers. Now i want to add all the numbers that are generated. What is the code to add them [closed]

Use a total variable and add the generated number to the total import random x = 0 total = 0 while x<10: number = random.randrange(1,10) print(number) total += number x=x+1 print(total) 0 solved i’ve generated random numbers. Now i want to add all the numbers that are generated. What is the code to add them … Read more