[Solved] How to split string in list [closed]

You should know there are two nested list, so there should be two nested for loop to iterate the list. And you should use another for loop to iterate the split() result. The code may be like this: lines = [[‘Name0, Location0’, ‘Phone number0’], [‘Name1, Location1’, ‘Phone number1’]] result = [] for line in lines: … Read more

[Solved] Fetching specific dict values via Python script/code

You have dictionary with list so you will need for-loop (or indexes ie. [0]) to get values. And because you have nested dictionares so you will have to use all keys to get nested value. data = {‘Response’: {‘effective-configuration’: {‘default-zone-access’: 1, ‘cfg-action’: 0, ‘db-max’: 1045274, ‘db-avail’: 1041908, ‘db-committed’: 1268, ‘db-transaction’: 0, ‘db-chassis-wide-committed’: 2280, ‘transaction-token’: 0, … Read more

[Solved] Using returned outputs from one function in another in Python

I would rewrite the main function to be something like: def GetStudentInput(): score = 0 for i in range (4): print(“Mrs Pearson’s Class Test Score Data”) name = CheckStringInput(“What’s Your Name: “) score += CheckNumericInput(“What’s Your Score: “) print(score) This eliminates the need for an extra function and avoids using a list since you don’t … Read more

[Solved] Writing and reading files [duplicate]

that is because you have entered a wrong file mode. You used r which stands for reading while you should use the w for the writing. That code should work. a = open(“movies.txt”,”rw”) a.write(“EndGame”) a.close() 3 solved Writing and reading files [duplicate]

[Solved] Arrays in Python [closed]

I can safely assume you want to know how to create a dictionary, and how to iterate through it. To create a dictionary: States = {‘Alabama’: ‘.05’, ‘Iowa’: ‘0.04’} To loop through it: for key in States: if key == stateName: #States[key] will return the value associated with the key, ex .05 for Alabama Hope … Read more

[Solved] Python: 2.5.1 Painting a Wall

Maybe I am missing something here, but if 350 sq ft requires 1 gallon, then 250 sq ft will require 250/350 gallons. So you are being asked (I suppose) to request the area from the user and calculate the paint required for that area. wall_area=float(input(“How big is your wall in square feet? “)) gallons_paint = … Read more

[Solved] String out of index

Different methods can be used for removing leading and trailing spaces, for converting multiple spaces to one and to remove spaces before exclamation mark, comma etc: mystr = ” Hello . To , the world ! ” print(mystr) mystr = mystr.strip() # remove leading and trailing spaces import re # regex module mystr = re.sub(r’\s+’,” … Read more

[Solved] Attempted relative import beyond toplevel package in django

Try this in your models: #Remove the import statement: from blog.models import sighinmodel #Then, inside your model user = models.ForeignKey(‘blog.sighinmodel’ , on_delete = None) Also, I would like to point out that this is not the correct way of importing other modules in your models.py . You should do like this: from appname.models import ModelName … Read more

[Solved] Can someone help me make my program case unsensitive? [closed]

The function lower returns the converted string and doesn’t convert the string self. You should use lower here: splitted = my_string.lower().split() Optimization for your code: d = {} l=[] for i,j in enumerate(splitted): l.append(d.setdefault(j, i)) with open(“numbertext.txt”,”w”) as f: f.write(str(l)) solved Can someone help me make my program case unsensitive? [closed]