Syntax error in range function declaration [closed] - syntax-error

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
Error in range function syntax enter image description here
for x in range(20),
if x % 2 == 0
print x
else
print 'odd',
output:
File "<ipython-input-106-a3bbe30e4016>", line 1
for x in range(20),
^
SyntaxError: invalid syntax

just replace the comma in the first line by :
Then, in Python 3.x, write print("toto") instead of print "toto".
Finally, the end of an if condition needs a : (like in a foor or a while loop)
for x in range(20):
if x % 2 == 0:
print(x)
else:
print('odd')

Related

Quantitavely replace digit (as counter) with string in sed [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 months ago.
Improve this question
Let's say i have the following file:
balloons:
- 2
- 3
Each number above should represents how many times i want to print the string. So for example I would like to process this to output as following:
balloons:
- red
- red
- blue
- blue
- blue
I only have red and blue balloons. The digits will vary from one file to another, so my search string would be a simple regex search sed -e "/[[:digit:]]\+/ perform_my_action"
Try:
awk 'BEGIN{idx[2]="red"; idx[3]="blue"}
/^-[ \t]+[0-9]+/{for(i=1;i<=$2;i++) print idx[$2]; next}
1
' file

awk dictionary not storing value [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I have written an awk statement, and the "a" dictionary is not storing values properly for an unknown reason.
I have the following file:
cat lookup.txt
1 a
2 b
3 c
However when I write the following awk statement the "a" dictionary seems not to be storing values properly:
awk 'NR==FNR{a[$1]=$2;print a[$2];print $2}' lookup.txt
a
b
c
I would expect that statement to print as follows:
a
a
b
b
c
c
Any help would be greatly appreciated.
You store a[$1] but fetch a[$2]. When the program ends, the a array contains three records: a["1"] = "a", a["2"] = "b", and a["3"] = "c". When you fetch from the array, there are no elements a["a"], a["b"] and a["c"], so those values are printed as nulls. I think you probably want to print a[$1].

Indexing words in a file according to their line with AWK [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 2 years ago.
Improve this question
Suppose I have a file similar to the following:
hello
hello
hi
hi
hello
hey
I would like to find the indices of every unique line and using a comma as the indices separator. So ideally, the output would be like:
hello 1,2,5
hi 3,4
hey 6
What has been done in getting the value of lines by using the following codes,
{ arr[$0]++ }
END { for (i in arr) {
print i
}
}
the result is,
hey
hi
hello
Try using this script
{
words[$0] = words[$0] == "" ? FNR : words[$0] "," FNR # appends the line, sorting for the word
}
END { # once we are done reading the file
for (w in words) # for each word, the sorting order depends on awk internal variables.
{
print w, words[w] # prints the desired output
}
}
Please see Controlling Array Traversal for more details on how the words are going to be printed out and how to control it. For more details on FNR see What are NR and FNR.

reading csv that has punctuation on column names using pandas [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
i have a csv file as below only one column(cust_code) with quotation marks and each row also has quotations
“CUST_CODE”
“CST001001”
“CST000235”
“CST010231”
“CST010235”
“CST010231”
“CST010235”
“CST010231”
“CST040015”
i am tried to read this file in pandas and i'm getting error as
'utf-8' codec can't decode byte 0x93 in position 0: invalid start byte
also, i tried by passing encoding type as ascii and utf-8
but nothing worked
Try passing encoding='cp1252' instead. Make sure to swap out 'Documents\Book1.csv' with whatever your filepath to the file is below:
df = pd.read_csv('Documents\Book1.csv', encoding='cp1252')
df
“CUST_CODE”
0 “CST001001”
1 “CST000235”
2 “CST010231”
3 “CST010235”
4 “CST010231”
5 “CST010235”
6 “CST010231”
7 “CST040015”
Here is a wikipedia with more info about that encoding type: https://en.wikipedia.org/wiki/Windows-1252 . A quote from the Wikipedia article:
"...common result was that all the quotes and apostrophes (produced by "smart quotes" in word-processing software) were replaced with question marks or boxes on non-Windows operating systems, making text difficult to read."

Input Mask start with letter C in VB.net [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I would like to create an input mask which looks like this C-HG__.
But because C represent option character or space in masking (VB.net). It wouldn't let me.
Please assist.
Try using the escape element: \
MSDN has a fairly nice write-up. Here's an excerpt:
\
Escape. Escapes a mask character, turning it into a literal. "\\" is the escape sequence for a backslash.
Possible duplicate with this question and/or this question.