[Solved] Str object has no attribute “add”

You assigned a string to the operator name: operator = randomOp[0] You are now masking the operator module. Don’t re-use names like that, because the next iteration of your for loop operator.add now tries to look up the add attribute on that string (so one of ‘+’, ‘-‘ or ‘*’, whatever the first iteration picked … Read more

[Solved] Delete lines from text file – python [closed]

This answer is assuredly overkill for your simple line selection problem, but it illustrates a nice property of Python: Often a very generalized pattern of behavior or processing can be very generally stated in a way that goes well beyond the original use case. And instead of creating a one-time tool, you can create very … Read more

[Solved] How to execute my code block by block?

Since ipython has already been discounted, I’m not sure this answer will be better. But I will tell you the two things that I do. I drop into the debugger at the point where I want to “try out” something, so the code will run up to that point, and then drop me into the … Read more

[Solved] Translate a string using a character map [closed]

The built-in function you seem to be looking for is str.translate: S.translate(table [,deletechars]) -> string Return a copy of the string S, where all characters occurring in the optional argument deletechars are removed, and the remaining characters have been mapped through the given translation table, which must be a string of length 256 or None. … Read more

[Solved] i need help adding the leap year functionality into my python program [closed]

Roll-your-own parser code is silly. Python has batteries included for this: import datetime repeat = True datestr = raw_input(‘Enter a date in the format MM/DD/YYYY’) while repeat: try: # Parse to datetime, then convert to date since that’s all you use date = datetime.datetime.strptime(datestr, ‘%m/%d/%Y’).date() except ValueError: pass # Handle bad dates in common code … Read more

[Solved] Find same elements in a list, and then change these elemens to tuple (f.e. 2 to (2,1))

To just add a count you could keep a set of itertools.count objects in a defaultdict: from itertools import count from collections import defaultdict counters = defaultdict(lambda: count(1)) result = [(n, next(counters[n])) for n in inputlist] but this would add counts to all elements in your list: >>> from itertools import count >>> from collections … Read more

[Solved] How can i fix concatenate tuple (not “list”) to tuple

You forgot to call the conversion function for some parameter in your function. I tested and corrected your code, call it this way: is_verified = verified( convert(data[‘k_signer’]), data[‘d_pk’], convert(data[‘d_signer’]), data[‘sig’], convert(data[‘addr’]), convert(data[‘seed’]), convert(data[‘data’]) ) solved How can i fix concatenate tuple (not “list”) to tuple

[Solved] Python Regex starting with hashtag

Just split by a newline and get the first element: test_str = “# <init> (Lorg/cyanogenmod/audiofx/ActivityMusic;)V\n , 0 iput-object v1, v0, Lorg/cyanogenmod/audiofx/ActivityMusic$11;->this$0 Lorg/cyanogenmod/audiofx/ActivityMusic;\n , 4 invoke-direct v0, Ljava/lang/Object;-><init>()V\n , a return-void ” print(test_str.split(‘\n’)[0]) See demo Output: # <init> (Lorg/cyanogenmod/audiofx/ActivityMusic;)V. If it is not the first line: A non-regex way: test_str = “some string\n# <init> (Lorg/cyanogenmod/audiofx/ActivityMusic;)V\n , … Read more

[Solved] Make list of strings uppercase and fill up strings with less than 5 characters [closed]

Pointing out the mistakes/unnecessary lines in your code: The line split = strings.split().upper() is erroneous and at the same time unnecessary as you are mistakenly using strings (list) instead of string (string literal). Also, you can use len(string) directly instead of splitting the string into a list and finding the length of list. result.append(char * … Read more