[Solved] Find the lowest value in dict [closed]

The one-line answer using the min function with personalized key would be min(chars_dict, key=lambda(item): chars_dict[item][‘hp’]) I think it’s the best solution, because you want to find the element with the lowest ‘hp’. Also, if you’re using dictionaries as containers with constant keys, it may be better to use custom classes. And if the keys in … Read more

[Solved] Error detection in basic code [closed]

First of all, you appear to have an IndentationError and there are extra space around the dot: def divide_list(list1, list2): list_out = [] for number1 in list1: for number2 in list2: list_out.append(float(number1) / float(number2)) return list_out # Test case print divide_list([1 ,2 ,3], [4 ,5 ,6]) I also added some PEP 8 formatting. Next time, … Read more

[Solved] Text Edit Change Variable Names [closed]

You may catch a few false matches, but this is the jist of it. It backs up the original files by adding a .bak extension, but make sure you have your own backup before overwriting valuable code. I assume these are JavaScript files? perl -i.bak -pe’s/\bm_(\w)/m\u$1/g’ *.js solved Text Edit Change Variable Names [closed]

[Solved] how to implement request GET in Python [closed]

If you don’t want to install an extra library, you can use pythons urllib2 library that is just as easy for something like connecting to a url. import urllib2 print urllib2.urlopen(“https://www.bitstamp.net/api/transactions/”).read() For parsing that, use pythons json library. solved how to implement request GET in Python [closed]

[Solved] How will it be fixed so that it can catch mentioned URL formats? [closed]

What I can notice, you expect the pattern to catch the website with or without http/https – this is not included in your expression. What is more, I am not sure what the purpose of \(* is – ((((((https://some.url.com will also be caught. Is https://½½½½½½½½½½½½ a valid url? It will be accepted. What about http://= … Read more

[Solved] How does Python iterate over a string? [duplicate]

The easiest way for me to think about this is to remember that the word ‘letter’ could easily be replaced with anything you want to call it, it’s just a placeholder. To illustrate, let’s replace ‘letter’ in your loop with the name ‘Dave’. for Dave in ‘Python’: print ‘Current letter : ‘, Dave There is … Read more

[Solved] How to calculate this mathematical expression in python? [closed]

I think you might be confused because it is showing scientific notation? ‘{}’.format() should help in that case. Xi = (70 + 1344736401384689745317259585614247891453883777111/315)% 115792089210356248762697446949407573529996955224135760342422259061068512044369 print(‘{0:f}’.format(Xi)) solved How to calculate this mathematical expression in python? [closed]

[Solved] For loop? For why and for how [closed]

When creating a loop, you must put a loop control variable. In this case it is char. You declare it when you are making your for loop. You can change that to whatever you want. I usually put “I”. The count +=1 isn’t necessary for a loop to work, this is only adding 1 every … Read more

[Solved] I am attempting to sort a single hand of cards by rank and suit with no builtins in Python 3 using the code I have [closed]

If I am following your code correctly, the variables card1 and card2 should contain some string like ‘AC’ or ‘5D’. It looks like you want to look at the suit and the number separately (value.find(card1[0] [0]) + ((suit.find(card1[0][1]))*20)). You only need one index here, not two. Check out the below example: >>> a=”AC” >>> a[0] … Read more

[Solved] how to create Dictionary within a dictionary in python

>>> import json >>> title, data = (‘Marks_Subjects ‘, “[[‘Time’, ‘maths’, ‘Science’, ‘english’], [‘2013-08-31-16’, 100, 50, 65]]”) >>> title, sub_title = title.split(‘_’) # Split ‘Mark’ and ‘Subjects’ >>> data = json.loads(data.replace(“‘”, ‘”‘)) # Deserialize the data list >>> data = dict(zip(*data)) # make a dict of the two lists >>> date = data.pop(‘Time’) # Extract … Read more

[Solved] Can we Write For loop as a function?

You could do this, but you probably shouldn’t: def forn(n): def new_func(func): for i in range(n): func(i) return func return new_func @forn(10) def f(i): print(i) or this: def forn(n, func) return [func(i) for i in range(n)] x = forn(10, lambda x: x**2) But these are more verbose and less readable than for i in range(10): … Read more