Posts
 
Reputation
Joined
Last Seen
Ranked #926
Strength to Increase Rep
+4
Strength to Decrease Rep
-1
100% Quality Score
Upvotes Received
7
Posts with Upvotes
6
Upvoting Members
6
Downvotes Received
0
Posts with Downvotes
0
Downvoting Members
0
3 Commented Posts
2 Endorsements
Ranked #621
Ranked #1K
~33.3K People Reached
Favorite Forums
Favorite Tags
Member Avatar for ItsAdZy
Member Avatar for RogueHaxor
0
1K
Member Avatar for Taruna_1

There are several ways to do this, including dictionaries, loops, etc. A simple solution would be to use a DSU (decorate, sort, undecorate). Let's assume you have the following list: my_list = ["I like apples", "Remember to eat your greens", Drink plenty of water"] We can use the split() method …

Member Avatar for Taruna_1
0
780
Member Avatar for Hamza_4

The **listdir()** function of the **os** module returns a list of all files in a given directory. If you combine that with the **fileinput** module's **input()** function, you can go over all the files in a given directory and replace whatever you wish. (hint: look at the *inplace* optional argument …

Member Avatar for vegaseat
0
244
Member Avatar for valorien

Hi Everyone. I'd appreciate your help writing better code. I have a list of ~1000 values: list_of_values = [0x123D, 0x844F, 0x33E9, ....., 0xFFFF, 0xFFFF, 0xFFFF] The last values in the list will always be 0xFFFF, but I don't know how many exactly. What I want is to get rid of …

Member Avatar for valorien
0
151
Member Avatar for deepthought

OP, I'm guesssing you have something like this (maybe more than 4 letters per item): list_of_hex = ['12AF', 'B3D9', 'A5CC', '6EA1\n', '298F', 'A005\n', ...] You want a new list of ints, but can't convert the items with the trailing '\n'. You could do several things, but here's a quick and …

Member Avatar for deepthought
0
400
Member Avatar for valorien

Hi Everyone, I have a list of numbers I'm trying to write to a file, which I want to be a binary file. Here's my code: nums = [0x1234, 0x5678, 0xabcd, 63, 44] with open('filename', 'wb') as bin_file: for number in nums: bin_file.write(number) The problem is that I keep getting …

Member Avatar for valorien
0
541
Member Avatar for pwolf

It seems like you're returning a tuple and not a string. try this and see what happens: [CODE]for item in pairwiseScore("ATTCGT", "ATCTAT"): print(item)[/CODE] or maybe you could try returning str(return value) in the function itself. Good Luck.

Member Avatar for TrustyTony
0
1K
Member Avatar for lundon

Try placing the next line at the beginning of your python script: [CODE]#!/usr/bin/env python[/CODE] Then just call the script from the terminal: [CODE]./path_to_script/script.py[/CODE] What happens?

Member Avatar for Trentacle
0
159
Member Avatar for zurk91

Have a look at the built-in split() method. It will allow you to create a list composed of the values you need - [url]http://www.tutorialspoint.com/python/string_split.htm[/url] to check if an indexed item is empty, you could try checking if item == " " Good luck.

Member Avatar for valorien
0
213
Member Avatar for Cenchrus

argv is a list containing the arguments passed to the python interpreter when called from a command line. For example, let's look at this script: [CODE] # test.py from sys import argv print(argv[0]) print(argv[1]) print(argv[2]) print(argv[3]) [/CODE] command line call: [CODE]test.py david 8 jenny[/CODE] output: [CODE]>>> test.py david 8 jenny[/CODE] …

Member Avatar for Cenchrus
0
5K
Member Avatar for python123456

First of all let's deal with the ConvertEnglish() function: The argument will probably be an int ('Number'), and it seems like you just need to return [CODE]numEnglish[Number][/CODE] As for the englishDigits() function: You're first step is right - you should isolate the rightmost digit. The second step however should pass …

Member Avatar for TrustyTony
0
2K
Member Avatar for junoh1991

Here's my quick and dirty solution: [CODE]list1= ['NNW 30', 'SE 15', 'SSW 60', 'NNE 70', 'N 10'] for index, item in enumerate(list1): if item.startswith('N'): list1[index] = "+" + item[-2:] elif item.startswith('S'): list1[index] = "-" + item[-2:] print(list1)[/CODE] Notice the use of startswith(), and the negative used to slice the letters …

Member Avatar for valorien
0
4K
Member Avatar for vlady

[CODE] [I][B]position=old_mark.index[old_mark][/B][/I] # are you sure old_mark has an index....? [/CODE] I'm not sure what you're trying to do here, but remember you can always replace the value in a dictionary pair by doing: [CODE]dic[old_key] = new_value[/CODE] Good luck :-)

Member Avatar for valorien
0
173
Member Avatar for Kitson

First things first, I would recommend opening files this way: [CODE] with open(filename) as file: """ Do some stuff """ [/CODE] This guarantees that no matter what happens with your code (unexpected error, hangs, etc.) the file will always be closed properly. As for the other tasks - once you've …

Member Avatar for valorien
0
206
Member Avatar for valorien

Hi Everyone :cool: What is the best way to represent, modify, and perform calculations with hexadecimal values (for instance, byte addresses) in Python? It seems every time I play with hex numbers, I'm always getting the result as a string or regular int type. case in point: Let's say I …

Member Avatar for Gribouillis
0
14K
Member Avatar for valorien

Hi Everyone :-) I'm writing a small Python script that invokes the Linux shell and runs some BASH commands in it. My problem is, I can't seem to use the output and store it in a Python variable. Here's what i'm trying: [CODE] import subprocess value = subprocess.call("ls -la", shell=True) …

Member Avatar for d5e5
0
3K
Member Avatar for valorien

Hi everyone, Just started programming in Python and iI'm already starting to like this language very much. I have a problem with a program I wrote last night - I'm trying to ping a certain host using [CODE]os.popen("ping xxx.xxx.xxx.xxx"[/CODE] and then read the %errorlevel% from my system using [CODE]result = …

Member Avatar for Ene Uran
0
1K