Quantcast
Channel: User Liju - Stack Overflow
Browsing all 35 articles
Browse latest View live

Comment by Liju on How do I have multiple optional inputs?

Try like this x.lower().strip() in ["yes", "y"]

View Article



Comment by Liju on Restarting a python tcpserver based on sockerserver library

Its 4 mins by default. which twice of MSL. check this question in microsoft doc. learn.microsoft.com/en-us/answers/questions/230227/…

View Article

Comment by Liju on How to find the lowest difference between two numbers from...

Sort them and iterate from 0 to n to check for least difference.

View Article

Comment by Liju on How to construct a graph (nodes and edges) in Python?

Customize the the class node, as per your requirements. and assign the features to them.

View Article

Comment by Liju on Split an array based on whether the elements occur in...

is it guaranteed that there will be only one element, common in both the arrays.?

View Article


Comment by Liju on Split an array based on whether the elements occur in...

But in the question comments, you confirmed, there will be only one number in common..!! here there are 2 common numbers 2 and 4.

View Article

Comment by Liju on Indexing consecutive values that sum to a target value

Try using list_values=[i-1,i] in place of those lines with numbers.index.

View Article

Comment by Liju on Indexing consecutive values that sum to a target value

Yeah. thats true.

View Article


Comment by Liju on Does python lambda provides performance advantage in large...

As far as I know, I see no difference at all in execution.

View Article


Answer by Liju for How to extract several values from a string with regex in...

You can use below regex to find key value pairs with findall(). then join them with =([a-zA-Z ]+):(.*?)(?:,|$)Demo hereSample programimport reinputs=["RB2 F 27/0/31 0/32, R8 28/31/120 2/0/2","TYPE...

View Article

Answer by Liju for Date matching not working on date and object?

In above case, you are comparing 'String' with Date object. which will always return False.Instead, converting the string to Date, and then comparing will give correct result.Check below code.if...

View Article

Answer by Liju for I am trying to make there be a list within a list and then...

As @IamFr0ssT already pointed out, you are emptying out xaxis and yaxis at every iteration. and assigning ships to ocean with only y axis.Correcting above, below is a complete code.import randomocean =...

View Article

Answer by Liju for How to do the reversed eight queens problem (if a pair hit...

Below code may help.class queen: def __init__(self,x,y): self.x=int(x) self.y=int(y) def is_horizontal_threat(self,new_queen): if self.x==new_queen.x: return True return False def...

View Article


Answer by Liju for calling a function from a function object in python

You can call the original function like a() in this case.

View Article

Answer by Liju for How can i iterate through a python dict and reach easily...

You can use recursion in this case.Below is a sample code.graph={'Node': [0, 0, 0],'children': [{'Node': [1, 0, 0],'children': [{'Node': [2, 0, 0], 'children': []}, {'Node': [1, 1, 0], 'children': []},...

View Article


Answer by Liju for First occurrence of a positive integer using binary search

Below code will help.def findFirstOccurrence(arr): left,right=0,len(arr)-1 while not((left==right) or (right==left+1)): mid=(left+right)//2 if arr[mid]>0: right=mid else: left=mid if arr[left]>0:...

View Article

Answer by Liju for New to Python, can someone please explain why these two...

The second approach will eliminate duplicates while merging, but the first one will not.Hence the difference in the sum.

View Article


Python ssl socket server SSLV3_ALERT_CERTIFICATE_UNKNOWN issue

I am writing a python socket server with ssl and I am encountering certificate unknown error during ssl handshake.I have created private key and certificate with openssl req -x509 -newkey rsa:4096...

View Article

Answer by Liju for Unable to unpack values in Python

Please try using zip.for (i, j) in zip(list_dict, a.values()): print(i['id'], j)Output:5903032523805 abc5903031568925 xyz5902976332061 yyy

View Article

Answer by Liju for Python JSON/Dict Converting Key:Pair to Key=Pair

You can define your own wrapper over json, to produce the __str__ of your requirements.Below an example programimport jsonclass data: def __init__(self,text): self.text=text def __repr__(self):...

View Article
Browsing all 35 articles
Browse latest View live




Latest Images