Comment by Liju on How do I have multiple optional inputs?
Try like this x.lower().strip() in ["yes", "y"]
View ArticleComment 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 ArticleComment 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 ArticleComment 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 ArticleComment 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 ArticleComment 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 ArticleComment 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 ArticleComment 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer by Liju for calling a function from a function object in python
You can call the original function like a() in this case.
View ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticlePython 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 ArticleAnswer 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 ArticleAnswer 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
More Pages to Explore .....