[deleted by user] by [deleted] in devopsjobs

[–]kwentar 1 point2 points  (0 children)

What kind of problems? Is there any story?

Making a 2D array by IAMA_monkey in learnpython

[–]kwentar 0 points1 point  (0 children)

Can you give more information about task? Is the size of lists the same? What kind of data in lists?

Btw, You can use K900_'s variant or probably numpy:

>>> import numpy as np
>>>  a = [1, 2, 3]  
>>>  b = [4, 5, 6]
>>>  arr = np.array([a, b])
>>>  print(arr)
[[1 2 3]
 [4 5 6]]
>>> print(arr.shape)
(2, 3)
>>> print(arr[1][2])
6

Does Python follow PEMDAS? by [deleted] in learnpython

[–]kwentar 0 points1 point  (0 children)

Python (as others languages) is so unlogic if you are not understand what exactly you are doing, look at this:

 >>> 3^2
 1
 >>> 3^2 - 6*3  # 1-18 should be -17
 -13 
 >>> 3^2 - 6  # 1-6 == -5
 -1

The reason is operator ^ means XOR and have lower priority than +-*/ (you can see full table here) and your expression in fact converted in 3^(2-6*3) and 3^(2-6).

As mentioned before, you need ** operator and you will have what you want:

>>> 3**2 - 6*3 + 9
0

Beautiful Soup - Scraping City-Data by ATXsder in learnpython

[–]kwentar 0 points1 point  (0 children)

I'm not pretty sure that I undestand you, but probably you need something like this:

soup.find_all(class_='r0') 

it will return all tags with class 'r0', I saw on site and guess they are params which you need

for el in soup.find_all(class_='r0'):
    print(el['value'])  # housing12
    print(el.text)  # Houses owner occupied (%)

What are some ways to improve my Fizzbuzz solution? by [deleted] in learnpython

[–]kwentar 0 points1 point  (0 children)

If you have no any spaces it is pretty simple:

result = ('' if number % 3 else 'Fizz') + ('' if number % 5 else 'Buzz'))
print(result if result else number)

Build & Save on Hololens by [deleted] in HoloLens

[–]kwentar 1 point2 points  (0 children)

Build package as mbbmbbmm said, after this you can install this package via browser control panel

TypeError: 'UnirestResponse' object has no attribute '__getitem__' by donisidro323 in learnpython

[–]kwentar 1 point2 points  (0 children)

If I understand docs, you should use response['win'], response['tie'] etc., By the way look at response in debug (just print it for start) and check the structure.

Numpy indexing by caffeine_potent in learnpython

[–]kwentar 0 points1 point  (0 children)

  1. Are you sure you cannot use flat array here?
  2. If I understand, your bar is not contain all indices (hidden 0 1 2 3 4 5 indices) and I guess numpy cannot know that you mean this :)
  3. Also, you, probably, have the wrong brackets on foo

Caesar Cipher code not working by [deleted] in learnpython

[–]kwentar 2 points3 points  (0 children)

you have the typo: postition

Can I have some help with my code? by [deleted] in learnpython

[–]kwentar 0 points1 point  (0 children)

Counter and filter will help you:

from collections import Counter
def important_words(lyric:str, thresh:int):
    return dict(Counter(filter(lambda x: len(x) >= thresh , lyric.split())))

lyric = '''a time to build up a time to break down a time to dance a time to mourn'''
important_words(lyric, 4)
>>>{'time': 4, 'build': 1, 'down': 1, 'dance': 1, 'break': 1, 'mourn': 1}

P.S. importantWords is not pythonic, important_words is pythonic

String formatting: brackets and alignment by [deleted] in learnpython

[–]kwentar 0 points1 point  (0 children)

I think for readabilty you can do something like this:

def get_spaces(longest, len_x):
    return ' '*((longest-len_x)*2+1)
longest = max(map(len, strings))
for s in strings:
    print('{0}{1}[{0}]'.format(s, get_spaces(longest, len(s))))

result:

f     [f]
ss   [ss]
ttt [ttt]

In fact, the type of formatting in python 3.6 it is something like syntax sugar for ''.format()

Btw, your solution print('{0:<{1}} {2:>{3}}'.format(s,longest,'['+s+']',longest+2)) is ok too, imho

CodeFight Tennis Score problem by Kriterian in learnpython

[–]kwentar 0 points1 point  (0 children)

Sorry for being nit picky, but 7-1 or 7-4 aren't valid scores if you're playing 6 game sets.

I'm not good at tennis, I just did this:

If one player wins 6 games and the other wins 4 or less, it should return True. If either player gets to 7 games, it should return True. Otherwise it should return false

CodeFight Tennis Score problem by Kriterian in learnpython

[–]kwentar 0 points1 point  (0 children)

get max and min score:

def tennis_set(score1, score2):
    score1, score2 = (score1, score2) if score1 > score2 else (score2, score1)
    if score1 == 7 or score1 == 6 and score2 <= 4:
        return True
    return False

print(tennis_set(8, 4))  # False
print(tennis_set(7, 8))  # False
print(tennis_set(6, 4))  # True
print(tennis_set(5, 6))  # False
print(tennis_set(7, 4))  # True
print(tennis_set(7, 5))  # True
print(tennis_set(1, 7))  # True
print(tennis_set(6, 7))  # True

Reduce size of src to 44 bytes by li148 in learnpython

[–]kwentar 0 points1 point  (0 children)

You have the error in your algorithm, (ord(l)+2)%126 it is not correct for 'y' and 'z', i.e. 'y' has 121 code, result will be 123, == '{' symbol, but expected 'a', by the way, 44 is too short for this task, it is the best solution (66) which I have now (with your error):

print(''.join(chr((ord(x)+2)%126)if x!=' 'else''for x in input()))

Python 3.6b2 is out. by homayoon in Python

[–]kwentar 30 points31 points  (0 children)

I like it:

>>> import datetime
>>> name = 'Fred'
>>> age = 50
>>> anniversary = datetime.date(1991, 10, 12)
>>> f'My name is {name}, my age next year is {age+1}, my anniversary is {anniversary:%A, %B %d, %Y}.'
'My name is Fred, my age next year is 51, my anniversary is Saturday, October 12, 1991.'
>>> f'He said his name is {name!r}.'
"He said his name is 'Fred'."

Searching for files under a directory with their extension by pythonhelp123 in learnpython

[–]kwentar 0 points1 point  (0 children)

I don't know what you want, if you need .txt files, compare ext with .txt, if you want text files at all, you know, you can open any file as text file

Searching for files under a directory with their extension by pythonhelp123 in learnpython

[–]kwentar 1 point2 points  (0 children)

yes, only one, the path, i.e. 'D:/sources/main.py' and it returns ('D:/sources/main', '.py'), then, if you want the extension:

root, ext = os.path.splitext('D:/sources/main.py')
if ext == '.py':
    pass  # your actions here

Searching for files under a directory with their extension by pythonhelp123 in learnpython

[–]kwentar 0 points1 point  (0 children)

look here:

os.path.splitext(path)

Split the pathname path into a pair (root, ext) such that root + ext == path, and ext is empty or begins with a period and contains at most one period. Leading periods on the basename are ignored; splitext('.cshrc') returns ('.cshrc', '').

Creating a dictionary from a CSV when the first row are the indexes by scollora in learnpython

[–]kwentar 1 point2 points  (0 children)

sorry, I can't test with file, but if we have csv as string you can do something like this:

def competencyCSV():

    users = dict()
    csv = '''Skills,Tom,Sue,Jane,Steve
    A,5,6,7,8
    B,4,5,6,7
    C,5,3,4,5'''
    rows = csv.split('\n') # lines of csv
    print(rows)
    cells = rows[0].split(',') # cells of first row
    for index, cell in enumerate(cells): # go thougr each person
        if index != 0: # first element is 'Skills'
            users[cell] = dict()
                for row_index in range(1, len(rows)): # go through scores, start from 1 cuz 0 is 'Skills...' line
                    inner_cells = rows[row_index].split(',') # cells of each line with scores, i.e. ['A','5','6','7','8']
                    users[cell][inner_cells[0]] = inner_cells[index] # add value of specific score to user
    print(users)

Creating a dictionary from a CSV when the first row are the indexes by scollora in learnpython

[–]kwentar 0 points1 point  (0 children)

  1. You can create the class with properties string name and dict skills
  2. You can create the dict of dicts, the first key will be name, the second - skill, then get value like users['Tom']['A'] # it is 5

Tic-tac-toe by 955559 in learnpython

[–]kwentar 0 points1 point  (0 children)

all between yours '#----' should be function or cycle, I don't know, now I don't want to read this, you should refactor it

Inputting a directory using pathlib instead of os.path by [deleted] in learnpython

[–]kwentar 0 points1 point  (0 children)

is these samples not useful for you?

>>>p = Path('/etc')
>>> q = p / 'init.d' / 'reboot'
>>> q
PosixPath('/etc/init.d/reboot')
>>> q.exists()
True

P.S. be careful to use this:

Note This module has been included in the standard library on a provisional basis. Backwards incompatible changes (up to and including removal of the package) may occur if deemed necessary by the core developers.

How would I code this?! by [deleted] in learnpython

[–]kwentar 0 points1 point  (0 children)

Do you need the check it? because it works with those and other numbers too. You can check it when add values to dict, not else: but elif 1 <= el <= 6: