[Solved] Need a Python program Singular to Plural [closed]

Just make it so that it appends “s” unless the word ends with “y” or some other exception: def plural(word): wordlist = [] for char in word: wordlist.append(char) if word[len(word)-1] == “y”: wordlist[len(word)-1] = “ies” else: wordlist.append(“s”) word = “” for i in wordlist: word+=i return word print(plural(“STRING”)) solved Need a Python program Singular to … Read more

[Solved] Python split a string at an underscore

Assuming that you have a string with multiple instances of the same delimiter and you want to split at the nth delimiter, ignoring the others. Here’s a solution using just split and join, without complicated regular expressions. This might be a bit easier to adapt to other delimiters and particularly other values of n. def … Read more

[Solved] Removing a substring from a string in python

EDIT: to drop the end of the string starting from the character before the underscore, but preserving the extension you can use a regex: import re s = “ABC_Y6N02.20.0025D_BF3DAC.tgz.bin” print( re.sub(r”^(.*)[^_]_[^\.]*(\.tgz\.bin)$”, r”\1\2″,s ).lower()) returns abc_y6n02.20.0025.tgz.bin 1 solved Removing a substring from a string in python

[Solved] Python deduce best number among list of lists [closed]

Here is a function that works fine for all cases and return the list of all first candidates encountered if no choice can be made to separate them. def find_best(list_of_lists): i = 0 while len(list_of_lists[i]) == 0: i+=1 list_containing_candidates = list_of_lists[i][:] if len(list_containing_candidates) == 1 : return list_containing_candidates[0] else: if i+1 < len(list_of_lists): for next_list … Read more

[Solved] How to count elements in a list and return a dict? [duplicate]

Using no external modules and only the count, although there would be some redundancy using dict comprehension: d = {itm:L.count(itm) for itm in set(L)} If you are allowed to use external modules and do not need to implement everything on your own, you could use Python’s defaultdict which is delivered through the collections module: #!/usr/bin/env … Read more

[Solved] Filter list with complex expression

I believe this does what you want… arr = [[2,6,8],[1,4,7],[3,3,4],[2,4,9],[3,3,7]] foo = lambda arr, evenOdd, noDoubles: [ i for i in arr if not (evenOdd and (all(k % 2 == 1 for k in i) or all(k%2 == 0 for k in i))) and not (noDoubles and (len(i) != len(set(i))))] print(foo(arr, False, False)) print(foo(arr, True, … Read more

[Solved] basic python syntax [closed]

A C struct can be packed into flat binary data, which is what Python 2 calls a string. The struct module lets you take a string that represents one of these C structs, and “unpack” it into a Python data structure. To do so you call struct.unpack. You need to specify a format string (as … Read more

[Solved] A knowledge quiz with several questions in Sets [closed]

You could do something like this: fragen = [‘List all the planets in our solar system!’, ‘List all countries in the European Union!’, ‘List all DAX companies!’] antwortsätze = [{‘Merkur’, ‘Venus’, ‘Erde’, ‘Mars’}, {‘Belgien’, ‘Bulgarien’, ‘Deutschland’, ‘Frankreich’}, {‘Adidas’, ‘Airbus’, ‘Allianz’, ‘BASF’}] for frage, antworten in zip(fragen, antwortsätze): antwortenx = set() richtige = 0 versuche = … Read more

[Solved] Bringing a city in form of a graph in python [closed]

https://opendata.cityofnewyork.us/data/ Publicly available datasets are available, in xlsx format, that detail current zoning, events, shops, registrations, etc. for the city in the link above. import pandas as pd df = pd.read_excel (r’Path where the Excel file is stored\File name.xlsx’, sheet_name=”your Excel sheet name”) Utilize Pandas as an alternative for importing your data into Python. solved … Read more