[Solved] Replace text inside .txt file or .xml file using loop [closed]

Using xml linq : using System; using System.Collections.Generic; using System.Collections; using System.Linq; using System.Text; using System.Xml; using System.Xml.Linq; namespace ConsoleApplication { class Program { static void Main(string[] args) { string xml = @”<Root> <Tag1> <USA></USA> <UK></UK> </Tag1> <Tag2> <FRA></FRA> <USA></USA> </Tag2> </Root>”; XDocument doc = XDocument.Parse(xml); List<XElement> tags = doc.Descendants().Where(x => x.Name.LocalName.StartsWith(“Tag”)).ToList(); List<string> countries = … Read more

[Solved] Python Indentation Error [closed]

The problem arises from the fact that python doesn’t like it when you mix tabs and spaces for indentation. Python relies on whitespace a LOT to figure out the levels of indentation, and hence scope. As a result, when you have a line that has two TABs on it, followed by a line with 4 … Read more

[Solved] Count Running and Stopped Ec2 Instances with AWS Lambda

Here’s some code that retrieves a list of instances and count the number of stopped and running instances: import boto3 def lambda_handler(event, context): ec2_resource = boto3.resource(‘ec2’) instances = [instance.state[“Name”] for instance in ec2_resource.instances.all()] print(‘Running: ‘, instances.count(‘running’)) print(‘Stopped: ‘, instances.count(‘stopped’)) The call to ec2_resource.instances.all() retrieves a list of all instances, and there is a state attribute … Read more

[Solved] Python Regex punctuation recognition

After minimizing your example we have: re.findall(r”/\,\b”, “/NN ,/, breeding/VBG Lilacs/NNP out/RB of/IN the/DT dead/JJ land/NN”) And it does not match for obvious reasons: there is no beginning of the word immediately after the comma. 2 solved Python Regex punctuation recognition

[Solved] Splitting line on python

Let us say you have splitted_result = [‘/media/My’, ‘Passport/fileName1’] Then you can do a simple join >>> [‘ ‘.join(splitted_result)] [‘/media/My Passport/fileName1’] This will output a list as its result. solved Splitting line on python

[Solved] Counting percentage of element occurence from an attribute in a class. Python

With for element in range(len(atm_transaction_list)):, you are iterating over integers in a range. This is generally used when you want to work with indices. However, you’re not doing that. Simply iterate over the transaction list itself, with for transaction in atm_transaction_list:. Each transaction will then be a Transaction object. I would also recommend storing your … Read more

[Solved] Python – Read and split every “:” and add into value

The string ‘split’ function takes a seprarator as an argument (https://docs.python.org/2/library/stdtypes.html#str.split). You might want to call the function like this: value = “hello:world:how:are:you”.split(“:”) And it will give you a list of items: [‘hello’,’world’,’how’,’are’,’you’] You can access them by simply using their index like this: value[0] # is ‘hello’ value[1] # is ‘world’ and so on. … Read more

[Solved] Have an issue with input command

For something to be a string in Python, it needs quotes around it. Right now Python thinks that O etc. are variables. Fixed: x = input(“Enter your blood type: “) if x == ‘O’: for y in range(6): print(“O O O O O O”) elif x == ‘A’: for y in range(6): print(“A A A … Read more

[Solved] Looping in Python

You could put everything in a while loop which could repeat forever or until a user types a certain phrase. import math import sys import os print (“This program will calculate the area, height and perimeter of the Triangles: Scalene, Isosceles, Equilateral and a Right Angled Triangle.”) while True: # calculate the perimeter print (“Please … Read more