Python Forum
Lists first item is a number however i cant compare it with an int getting syntax err
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Lists first item is a number however i cant compare it with an int getting syntax err
#1
Hello everyone,

when i try to compare list first element i am getting a syntax error. "if satırsayısı2=isimsatırlistesi[0]" this list is made of " isimsatırlistesi.append(int(satırsayısı))" so all the elements of the list are int not sure how to avoid this. Any suggestions ?


fhand=open("arb1.txt")

satırsayısı=0
isimsatırlistesi=list()
for line in fhand:
    satırsayısı=satırsayısı+1
    if line.startswith("Adres"):
        isimsatırlistesi.append(int(satırsayısı))

adressatırı=list()
satırsayısı2=0
satırdakikelimesayısı=0
for line in fhand:
        satırsayısı2=satırsayısı+1
        if satırsayısı2=isimsatırlistesi[0] # getting the error here
            print(line)
Reply
#2
Use ==
if satırsayısı2==isimsatırlistesi[0]: 
Reply
#3
Still getting the error thanks for the comment tough.
Reply
#4
I am able to run your code without error

This code wont print anything due to satırsayısı2=satırsayısı+1
 adressatırı=list()
satırsayısı2=0
satırdakikelimesayısı=0
for line in fhand:
        satırsayısı2=satırsayısı+1
        if satırsayısı2=isimsatırlistesi[0] # getting the error here
            print(line)
Reply
#5
Thanks alot looks like i forgot to use ":" at the end of if. It works thanks a bunch :).
if satırsayısı2==isimsatırlistesi[0]:

(Apr-22-2020, 09:58 AM)anbu23 Wrote: I am able to run your code without error

This code wont print anything due to satırsayısı2=satırsayısı+1
 adressatırı=list()
satırsayısı2=0
satırdakikelimesayısı=0
for line in fhand:
        satırsayısı2=satırsayısı+1
        if satırsayısı2=isimsatırlistesi[0] # getting the error here
            print(line)

Thanks for the heads up :)

now it is " satırsayısı2=satırsayısı2+1"
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Compare two lists (with intersections). wnesbv 0 954 Jul-06-2022, 09:07 AM
Last Post: wnesbv
  Syntax when initializing empty lists Mark17 2 1,323 Jun-02-2022, 04:09 PM
Last Post: Mark17
  Remove an item from a list contained in another item in python CompleteNewb 19 5,551 Nov-11-2021, 06:43 AM
Last Post: Gribouillis
  Even number code syntax error MrCeez 1 2,246 May-02-2021, 06:43 PM
Last Post: Larz60+
  How do I add a number to every item in a list? john316 2 1,927 Oct-28-2020, 05:29 PM
Last Post: deanhystad
  Split dict of lists into smaller dicts of lists. pcs3rd 3 2,312 Sep-19-2020, 09:12 AM
Last Post: ibreeden
  Compare Two Lists and Replace Items In a List by Index nagymusic 2 2,847 May-10-2020, 05:28 AM
Last Post: deanhystad
  how to compare a list to a list of lists kevthew 1 1,774 Dec-22-2019, 11:43 AM
Last Post: ibreeden
  sort lists of lists with multiple criteria: similar values need to be treated equal stillsen 2 3,189 Mar-20-2019, 08:01 PM
Last Post: stillsen
  curious syntax with dictionary item inselbuch 3 2,725 Mar-09-2019, 04:21 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020