[Solved] write python code in single line

Since pythons list comprehensions are turing complete and require no line breaks, any program can be written as a python oneliner. If you enforce arbitrary restrictions (like “order of the statements” – what does that even mean? Execution order? First apperarance in sourcecode?), then the answer is: you can eliminate some linebreaks, but not all. … Read more

[Solved] C# BigInteger remainder as fraction

This seems to work: BigInteger a = new(5678); BigInteger b = new(1234); BigInteger div = BigInteger.DivRem(a, b, out BigInteger rem); var decimalDigits = new List<BigInteger>(); while (rem != 0 && decimalDigits.Count < 10) { rem *= 10; decimalDigits.Add(BigInteger.DivRem(rem, b, out rem)); } Console.WriteLine($”{div}.{string.Concat(decimalDigits)}”); This is pretty much just an implementation of long division. 1 solved … Read more

[Solved] OR and AND operator confusion in Javascript [closed]

If it helps you to understand, you can rewrite it from AND to OR: while (command != “quit” && command != “q”) { // do job } is equivalent to while (!(command === “quit” || command === “q”)) { // do job } https://en.wikipedia.org/wiki/De_Morgan%27s_laws 5 solved OR and AND operator confusion in Javascript [closed]

[Solved] Find and list duplicates in an unordered array consisting of 10,000,000,00 elements

Here you go class MyValues{ public int i = 1; private String value = null; public MyValues(String v){ value = v; } int hashCode() { return value.length; } boolean equals(Object obj){ return obj.equals(value); } } Now iterate for duplicates private Set<MyValues> values = new TreeSet<MyValues>(); for(String s : duplicatArray){ MyValues v = new MyValues(s); if … Read more

[Solved] Filters collection unavailable on *some* versions of IE9

I downloaded the gadget and see no problems. I see the transitions (dissolve) and control bar transparency is also there. My user agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0) I’m running Win7 x64 SP1, IE9 32bit. I do not have many addons, just a few including Shockwave, Kaspersky AV Broswer helpers, MS … Read more

[Solved] Create email with the firsts letters of the name [closed]

Here’s some “python magic” name = [‘Elon Reeve Musk’] f”{”.join(filter(str.isupper, name[0]))}@company.com”.lower() >>> [email protected] Whether this is better than your method is debatable. Most of the time a few lines of easy to read code is better than a one line hack. My recommendation would be name = [‘Elon Reeve Musk’] initials=””.join(word[0] for word in name[0].split()) … Read more

[Solved] Find if string is in other string

I think you are looking for something like this class Program { static void Main(string[] args) { string attrs = “AAA,BBB,CCC,DDD”; List<Vehicle> vehiclesSort = new List<Vehicle>(); vehiclesSort.Add(new Vehicle(attrs)); vehiclesSort.Add(new Vehicle(“bbb”)); vehiclesSort = vehiclesSort.Where(o => o.attr.Contains(attrs)).ToList(); foreach (var VARIABLE in vehiclesSort) { Console.WriteLine(VARIABLE.attr); } } } public class Vehicle { public Vehicle(string attr1) { this.attr = … Read more

[Solved] find number of 1 and 0 combinations in two columns

Assuming you have a pandas dataframe, one option is to use pandas.crosstab to return another dataframe: import pandas as pd df = pd.read_csv(‘file.csv’) res = pd.crosstab(df[‘X’], df[‘Y’]) print(res) Y 0 1 X 0 3 7 1 1 3 A collections.Counter solution is also possible if a dictionary result is required: res = Counter(zip(df[‘X’].values, df[‘Y’].values)) 4 … Read more